点击时显示键盘。当您单击屏幕的另一个区域时,键盘将被隐藏。单击屏幕的其他区域时是否可以阻止隐藏键盘?
答案 0 :(得分:1)
以下是隐藏键盘的代码
public void hideKeyboard(View view)// pass your main view {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
}
答案 1 :(得分:1)
尝试隐藏键盘
public static void hideSoftKeyboard(Activity context) {
InputMethodManager inputManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputManager != null)
inputManager.hideSoftInputFromWindow(context.getWindow()
.getDecorView().getApplicationWindowToken(), 0);
context.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}