Sujit Sujit - 1 year ago 73
Android Question

hide default keyboard on click in android

i want to hide the soft keyboard when i click out side of editbox in a screen. how can i do this?


To forcibly hide the keyboard you would use the following code... I put it in a method called 'hideSoftKeyboard()'. As mentioned by Falmarri, the softkeyboard should hide itself when you click out of it. However, if you call this method in an 'onClick()' of another item, it will forcibly close the keyboard.

private void hideSoftKeyboard(){
    if(getCurrentFocus()!=null && getCurrentFocus() instanceof EditText){
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(yourEditTextHere.getWindowToken(), 0);