How to close Android Soft KeyBoard programmatically?

前端 未结 14 1305
别跟我提以往
别跟我提以往 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

    I have tested and this is working:

    ...
    //to show soft keyboard
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    
    //to hide it, call the method again
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    

    By the way, the second parameter of your code is not right, please have a look at here.

提交回复
热议问题