android softkeyboard showSoftInput vs toggleSoftInput

前端 未结 8 954
一向
一向 2020-12-29 20:47

showSoftInput() doesn\'t show the keyboard for me, but toggleSoftInput() does. I saw some other post that said to disable the hard keyboard when us

8条回答
  •  执念已碎
    2020-12-29 21:28

    I know this post is pretty old, but for those who came for answers from this date and none of the above worked. The code below worked for me on an Activity when an Alert Dialog popped up.

    InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    

    to show keyboard:

    keyboard.toggleSoftInput(editText.getPaintFlags(), 0);
    

    to hide keyboard:

    keyboard.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    

提交回复
热议问题