android softkeyboard showSoftInput vs toggleSoftInput

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

    Show Keyboard + focus and also if you want to Hide the keyboard

    @Override
    public void onResume () {
        super.onResume();
    
        inputSearch.setFocusableInTouchMode(true);
        inputSearch.requestFocus();
    
        // Show Keyboard
        InputMethodManager imm = (InputMethodManager) getSherlockActivity().getSystemService(
                Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(inputSearch, InputMethodManager.SHOW_IMPLICIT);
    }
    

    P.S inputSearch = (EditText) getSherlockActivity().findViewById(R.id.inputSearch);

        // Hide Keyboard
    InputMethodManager imm = (InputMethodManager) getSherlockActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(inputSearch.getWindowToken(), 0);
    

提交回复
热议问题