我尝试了很多方法,但没有一种方法可行或可能用于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?***
}
}
由于
答案 0 :(得分:1)
在onCreate()方法
中设置布局后,请尝试以下代码EditText edtView=(EditText)findViewById(R.id.editText);
edtView.setInputType(0);
触摸或对焦时,SoftInputKeyboard不会弹出。希望它有所帮助
答案 1 :(得分:0)
您可以通过调用此方法隐藏软键盘
public void hideSoftKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity
.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
答案 2 :(得分:0)
View.OnFocusChangeListener focusListener = (v, hasFocus) -> {
if (hasFocus) {
InputMethodManager inputMethodManager = (InputMethodManager) context
.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
};