禁止自动弹出之sdk解决方案:
在AndroidManifest.xml里面
选择那个acitivity, 把他的windowsoftinputmode设置成stateHidden和
adjustUnspecified
Java代码
<activity android:name=".MyMsgDetailActivity" android:configChanges="orientation|keyboardHidden" android:windowSoftInputMode="adjustUnspecified|stateHidden"/>
禁止自动弹出之自定义解决:
进入activity时,使EditText不能获得聚焦就行了,方法如下:
在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus。
<TextView
android:id="@+id/text_notuse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true" />
TextView textView = (TextView)findViewById(R.id.text_notuse);
textView.requestFocus();
注意TextView不要设置Visiable=gone,否则会失效。
自动弹出解决方案:
1:
EditText editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
InputMethodManager inputManager =
(InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(editText, 0);
首先要对指定的输入框请求焦点。然后调用输入管理器弹出软键盘。
警告:对于刚跳到一个新的界面就要弹出软键盘的情况上述代码可能由于界面为加载完全而无法弹出软键盘。此时应该适当的延迟弹出软键盘如998毫秒(保证界面的数据加载完成)。实例代码如下:
[代码]java代码:
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run() {
InputMethodManager inputManager =
(InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(editText, 0);
}
}, 998);