Hide keyboard when navigating from a fragment to another

后端 未结 5 1452
我寻月下人不归
我寻月下人不归 2021-01-30 16:17

I have a Fragment that contains an Edit Text. When the Edit Text is pressed, the keyboard is being shown. When pressed the Save button in the upper corner, the application retur

5条回答
  •  不知归路
    2021-01-30 17:11

    @Override
        public void onDestroyView() {
            super.onDestroyView();
            View view = getActivity().getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }
    

提交回复
热议问题