Hide to show and hide keyboard in DialogFragment

后端 未结 8 2195
花落未央
花落未央 2021-02-08 03:57

In my dialog fragment, I am able to show the keyboard using

getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT STATE_VISIBLE);
         


        
8条回答
  •  梦如初夏
    2021-02-08 04:53

    for hide soft keyboard, you can use this method:

    public void hideSoftKeyboard() {
            try {
                View windowToken = getDialog().getWindow().getDecorView().getRootView();
                InputMethodManager imm = (InputMethodManager) getDialog().getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow( windowToken.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            } catch (Exception ex) {
                Log.e(ex);
            }
        }
    

提交回复
热议问题