Android hides the input method keyboard (hideSoftInputFromInputMethod does not work)
In some cases, you need to forcibly hide the Android Input Keyboard. If the current keyboard is displayed, You Need To forcibly hide the Input Keyboard when you click the slide panel. Common online methods include:
1. InputMethodManager imm = (InputMethodManager) getActivity ()
. GetSystemService (Context. INPUT_METHOD_SERVICE );
Imm. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS );
This is to reverse the input method status. If the current status is not displayed, it is displayed. If it is displayed, it is hidden. Therefore, it does not conform to the application scenarios described in this article.
2. imm. hideSoftInputFromInputMethod (passwdEdit. getWindowToken (), 0 );
The test on Android is invalid.
3. imm. hideSoftInputFromInputMethod (getActivity (). getCurrentFocus (). getWindowToken (), 0 );
Tested by myself, it still does not work. Uncle, I wasted two hours for this small feature.
4,Imm. hideSoftInputFromWindow (passwdEdit. getWindowToken (), 0 );
After testing, this is the only valid method!
In addition, some people say:
InputMethodManager imm = (InputMethodManager) this
. GetSystemService (Context. INPUT_METHOD_SERVICE );
Boolean isOpen = imm. isActive ();
Log. I (TAG, "imm. isActive () =" + isOpen );
The above code is used to determine whether the keyboard of the current input method is visible. It is totally nonsense and isOpen is always true. It is hereby recorded.