[英]Android - hide keyboard input for EditText when focus (API >=17)
我嘗試了很多方法,但是都無法使用,或者可能不適合API <17。有人可以告訴我如何在焦點或單擊EditText時隱藏鍵盤嗎?
ViewGroup group = (ViewGroup)findViewById(R.id.f1entrygroup);
for (int i = 0, count = group.getChildCount(); i < count; ++i) {
View view = group.getChildAt(i);
if (view instanceof EditText) {
view.setOnFocusChangeListener(focusListener);
view.setOnClickListener(entryClickListener);
***//HOW TO DISABLE THE KEYBOARD POP UP AT HERE?***
}
}
謝謝
在onCreate()方法中設置布局后,嘗試以下代碼
EditText edtView=(EditText)findViewById(R.id.editText);
edtView.setInputType(0);
當您觸摸或聚焦時,SoftInputKeyboard不會彈出。 希望能幫助到你
您可以通過調用此方法隱藏軟鍵盤
public void hideSoftKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity
.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
View.OnFocusChangeListener focusListener = (v, hasFocus) -> {
if (hasFocus) {
InputMethodManager inputMethodManager = (InputMethodManager) context
.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.