部分内容来源于http://blog.csdn.net/cshichao/article/details/8536961  

一.产生原因

EditText自动获取到了焦点,所以弹出软键盘,so...解决问题的方法也就是不让他获取到焦点就行。


二.解决方法

(1)在父容器中添加这两段代码(亲测有效)

<span style="white-space:pre">		</span>android:focusable="true"
                android:focusableInTouchMode="true"

(2)在清单文件(AndroidMainifest)中添加  (亲测有效)

android:windowSoftInputMode="stateHidden"


(3)让EditText失去焦点(木有用,虽然确实代码是做清除焦点,但是确实没用,具体原因不明)

EditText edit = (EditText)findViewById(R.id.edit);  
edit.clearFocus(); 


(4)强制隐藏Android输入法窗口(木有用,具体原因不明)

EditText edit = (EditText)findViewById(R.id.edit);  
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);  
imm.hideSoftInputFromWindow(edit.getWindowToken(), 0); 



(5)让EditText永远不弹出软键盘(亲测有效)

EditText edit = (EditText)findViewById(R.id.edit);  
edit.setInputType(InputType.TYPE_NULL); 



Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐