Monday, October 3, 2011

How to hide soft keyboard programmatically in Android


To hide the virtual keyboard using InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field.

InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(AtmosAccountAuthenticationActivity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(editText.getWindowToken(), 0);

This will force the keyboard to be hidden in all situations. In some cases you will want to pass in InputMethodManager.HIDE_IMPLICIT_ONLY as the second parameter to ensure you only hide the keyboard when the user didn't explicitly force it to appear (by holding down menu).

No comments:

Post a Comment