Android click to close the keyboard
In the project, after editText gets the focus, a soft keyboard is automatically displayed. When it is disabled, you usually need to press the back key or click the button on the soft keyboard,
Even if the current activity has been completed, the soft keyboard still exists, which will affect the user experience.
There are currently many detailed methods on the Internet, such as clicking on other blank areas, and the soft keyboard will disappear. This is not required in our project, as long
Other operations are not blocked, and the keyboard disappears after the current Activity is disabled,
We will share with you two methods today:
// This method is hidden if it is displayed. If it is hidden, private void hintKbOne () {InputMethodManager imm = (InputMethodManager) getActivity () is displayed (). getSystemService (Context. INPUT_METHOD_SERVICE); // obtain the InputMethodManager instance if (imm. isActive () {// If you enable imm. toggleSoftInput (InputMethodManager. SHOW_IMPLICIT, InputMethodManager. HIDE_NOT_ALWAYS );}}
// This method only disables the soft keyboard private void hintKbTwo () {InputMethodManager imm = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE); if (imm. isActive () & getCurrentFocus ()! = Null) {if (getCurrentFocus (). getWindowToken ()! = Null) {imm. hideSoftInputFromWindow (getCurrentFocus (). getWindowToken (), InputMethodManager. HIDE_NOT_ALWAYS );}}}
When you need to click an event to close the keyboard, you only need to call the method.