有没有办法在不失去 EditText 焦点的情况下隐藏键盘

Is there a way to hide the keyboard without losing the focus of the 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();