简体   繁体   English

有没有一种方法可以隐藏键盘而不丢失EditText的焦点

[英]Is there a way to hide the keyboard without losing the focus of the EditText

When you click the back button, the keyboard hides itself but the focus on the edittext remains. 当您单击“后退”按钮时,键盘会隐藏起来,但焦点仍保留在edittext上。 How can I reproduce this behaviour? 如何重现此行为?

You can use this code to hide the keyboard: 您可以使用以下代码隐藏键盘:

getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
);

Or this one : 或者这个:

View view = this.getCurrentFocus();
if (view != null) {  
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

If the EditText loses the focus, simple write a simple command 如果EditText失去焦点,请简单地编写简单的命令

editText.requestFocus();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM