简体   繁体   中英

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. 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.requestFocus();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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