• support@answerspoint.com

Close/hide the Android Soft Keyboard


I have an EditText and a Button in my layout. After writing in the edit field and clicking on the Button, I want to hide the virtual keyboard. I assume that there's a simple, one- or two-liner to make this happen. Where can I find an example of it?



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

// Check if no view has focus:
View view = this.getCurrentFocus();
if (view != null) {  
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
  • answered 7 years ago
  • G John


Also useful for hiding the soft-keyboard is:


This can be used to suppress the soft-keyboard until the user actually touches the editText View.

  • answered 7 years ago
  • Gul Hafiz

Your Answer

    Facebook Share        
  • asked 8 years ago
  • viewed 1704 times
  • active 8 years ago

Best Rated Questions