【发布时间】:2017-08-20 11:08:53
【问题描述】:
当您单击后退按钮时,键盘会自行隐藏,但编辑文本上的焦点仍然存在。我怎样才能重现这种行为?
【问题讨论】:
标签: java android android-edittext keyboard focus
当您单击后退按钮时,键盘会自行隐藏,但编辑文本上的焦点仍然存在。我怎样才能重现这种行为?
【问题讨论】:
标签: java android android-edittext keyboard focus
您可以使用此代码隐藏键盘:
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();
【讨论】: