[英]Is there a way to hide the keyboard without losing the focus of the EditText
当您单击“后退”按钮时,键盘会隐藏起来,但焦点仍保留在edittext上。 如何重现此行为?
您可以使用以下代码隐藏键盘:
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
);
或者这个:
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
如果EditText失去焦点,请简单地编写简单的命令
editText.requestFocus();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.