How to close Android Soft KeyBoard programmatically?

前端 未结 14 1341
别跟我提以往
别跟我提以往 2020-12-02 16:33

I am currently showing softkeyboard using the following code

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
im         


        
14条回答
  •  佛祖请我去吃肉
    2020-12-02 17:07

    user942821's answer for hiding it works:

    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    

    But this also works for me to hide it:

    imm.toggleSoftInput(0, 0);
    

    You might also want to try:

    imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
    

    When using '0' in the first parameter sometimes the keyboard toggles on in the wrong places under weird circumstances that I haven't been able to figure out how to duplicate yet. I'm still testing this last example, but will update when I find out more.

    See toggleSoftInput documentation page for more information.

提交回复
热议问题