Android dismiss keyboard

后端 未结 9 588
面向向阳花
面向向阳花 2021-01-29 23:51

How do I dismiss the keyboard when a button is pressed?

9条回答
  •  不要未来只要你来
    2021-01-30 00:28

    The solution above doesn't work for all device and moreover it's using EditText as a parameter. This is my solution, just call this simple method:

    private void hideSoftKeyBoard() {
        InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    
        if(imm.isAcceptingText()) { // verify if the soft keyboard is open                      
            imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
        }
    }
    

提交回复
热议问题