Android: Hide Virtual Keyboard

If we want to hide the virtual keyboard at any point we can use the following code:

//hide the keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

The myEditText can be any view such as a TextView or a Button.

The getWindowToken() function will get a unique token identifying the window that the view is attached to.




1 Comment

Terrific work! This is the type of information that should be shared around the web. Shame on the search engines for not positioning this post higher!

Leave a Reply

Your email address will not be published. Required fields are marked *