[英]EditText inside a alertDialogue is not showing softkeyboard in Android
[英]Android: EditText inside Scrollview: block softkeyboard autoshow
当活动在滚动视图中有 EditText 时,软键盘会自动显示。
但是 EditText 不是 Activity 的主要功能。
创建Activity时如何防止SoftKeyboard自动显示?
有些事情不能解决问题:
添加代码来隐藏软键盘会导致重新显示它的问题:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
或在清单中: android:windowSoftInputMode="stateAlwaysHidden"
您只需删除EditText
焦点。
1-将android:windowSoftInputMode="stateHidden"
添加到清单中的活动标签
或者
2-使用this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
或者
3-使用edittext.clearFocus();
或者
4-套
android:focusable="true"
android:focusableInTouchMode="true"
另一种看法。
注意: edittext.clearFocus();
可能不起作用,因为它将焦点设置回活动中的另一个可聚焦视图,因此对于一个视图,它只是将焦点能力重置为同一视图。
你可以使用edittext.clearFocus();
或添加android:windowSoftInputMode="stateHidden"
您可以在 onCreate 方法中使用此代码...
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
阻止软键盘自动显示的正确方法是防止它专注于 EditText。
对于布局中的每个编辑文本:
onCreate()
editText = (EditText)findViewById(R.id.edittext);
editText.setFocusable(false);
在您的 xml 布局文件中:
<EditText
...
android:onClick="enableFocusable"
然后在java类中,一个方法...
public void enableFocusable(View view) {
editText.setFocusableInTouchMode(true);
editText.requestFocus();
if (view.requestFocus()) {
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.