[英]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.