Android: how to close explicitly displayed soft keyboard? -


I am displaying a dialog for text input and want to display a soft keyboard automatically if there is no hard keyboard Are there. To display it on my Samsung Galaxy Tab, I had to use SHOW_FORCED flag, SHOW_IMPLICIT flag did not work. Also, on the dialogue exclusion I want to turn off the keyboard if I am forcing its display. However, the code I'm using does not turn off the keyboard on my Galaxy Tab; I think this is because I showed the use of the flag clearly.

  / * From the Communicator / InputMethodManager imm = (InputMethodManager) getSystemService (context.INPUT_METHOD_SERVICE); ImmrerestInput (mEditText); // Display only if there is no hard keyboard outside of console configuration config = getResources (). GetConfiguration (); If (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {mForcedKeyboardDisplay = true; Imm.toggleSoftInput (InputMethodManager.SHOW_FORCED, 0); } / * OnDismiss () method * / // If we already compel the keyboard display, then force it to close (mForcedKeyboardDisplay) {InputMethodManager imm = (InputMethodManager) getSystemService (Context.INPUT_METHOD_SERVICE); ImmrerestInput (mEditText); Imm.hideSoftInputFromWindow (mEditText.getWindowToken (), InputMethodManager.HIDE_IMPLICIT_ONLY); // This is either //imm.hideSoftInputFromWindow (mEditText.getWindowToken (), InputMethodManager.HIDE_NOT_ALWAYS) does not work; // and not //imm.hideSoftInputFromWindow (mEditText.getWindowToken (), 0); }    

First of all, do not use toggleSoftInput () . This is the name that says - Toggles the status of the IME. If you really want to make sure that it is shown, then showSoftInputFromWindow () .

, there is no reason to call second restartInput () . When tapping on the text view to show showSoftInput () with the 0 flag. Actually here's the code:

If you can tap the text view to show IME, but your call is not working, then you really should know why your call is not working is . I do not strongly recommend using SHOW_FORCED - which is the specific behavior that I suspect you want (for example, if the user presses the home, the IME will be open, generally not desirable.)

The most likely reason for your call to hide IMEs does not work is that there is no input focus in your window at that point ... if possible, you will see a message in the log. In fact, be sure to check in logs anyway because messages are often printed when there are problems.

Comments