ProAnswers.org

How to close/hide the Android Soft Keyboard?

How to close/hide the Android Soft Keyboard?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field.

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).

Also useful for hiding the soft keyboard is:

getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

This can be used to suppress the keyboard until the user actually touches the edittext view.

try below code

[b]InputMethodManager [/b]inputManager = ([b]InputMethodManager[/b])            

  this.getSystemService([b]Context[/b].INPUT_METHOD_SERVICE); 

    inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),      

    [b]InputMethodManager[/b].HIDE_NOT_ALWAYS);

 

Where this is the context.