Android EditText gets the focus and automatically pops up the soft keyboard [perfect solution]

 

Copy this method into

    public void showSoftInputFromWindow(EditText editText){
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
        editText.requestFocus();
        CommunityFriendCircleActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }
CommunityFriendCircleActivity.this represents the current Activity. If you display the keyboard on the MainActivity interface, change it to MainActivity.this.

Just change it to whichever interface you want.

Just call it where you need it

 showSoftInputFromWindow(mEditText);//显示键盘

mEditText is the component corresponding to your edit box

 

Guess you like

Origin blog.csdn.net/weixin_44232136/article/details/93969545
Recommended