我遇到了这样的情况,我检查软键盘是否打开,并且我想在代码中关闭它,但是当我使用下面的代码时,它无法关闭键盘,因为代码找不到任何焦点,但是键盘仍然打开,那么我该怎么隐藏它呢?
private void hideSoftKeyboard() {
Activity activity = (Activity) sContext;
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
//((Activity) sContext).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
} else {
Log.i(sClassTag,"focus not found");
}
}
View view = this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); }
- CharuකInputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
- Charuක