android softkeyboard showSoftInput vs toggleSoftInput

前端 未结 8 1000
一向
一向 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:22

    public void hideKeyboard() {
        myTextView.setFocusable(true);
        myTextView.setFocusableInTouchMode(true);
        imm.hideSoftInputFromWindow(myTextView.getWindowToken(), 0);
    }
    

    WORKS

    public void hideKeyboard() {
        imm.hideSoftInputFromWindow(myTextView.getWindowToken(), 0);
    }
    

    DOES NOT WORK

    imm is dealt with earlier as I am using a Fragment so:

    Declare imm in the Fragment

    private InputMethodManager imm;
    

    Then in the fragment add:

    @Override
        public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        imm = (InputMethodManager)
        getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    }
    

    He says after 3 to 4 hours of research and failures !!

    Thanks user_CC ! :-)

    Phil

提交回复
热议问题