Hide to show and hide keyboard in DialogFragment

后端 未结 8 2202
花落未央
花落未央 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条回答
  •  -上瘾入骨i
    2021-02-08 04:55

    Hide it in DialogFragment onDestroyView() method:

     View view = getActivity().getCurrentFocus();
            if (view == null) view = new View(activity);
            InputMethodManager imm = (InputMethodManager)     getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
            if (imm == null) return;
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    

    maybe work.

提交回复
热议问题