Android automatically pops up the keyboard for EditText in Dialog

I want to automatically pop up the keyboard for the EditText in the Dialog, so that the user can directly input after the Dialog pops up, eliminating the need for one more operation. I checked it online, but the method didn't work for me. Maybe it’s useful to you. Share a blog: Android automatically pops up a soft keyboard while displaying Dialog;
later I found out that I wrote this code before, and I forgot which blog I copied it from...

private void setfocus(View view) {
    
    
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}

Then just call this function directly, for example:

setfocus(myEditText);

I hope useful to you.

Guess you like

Origin blog.csdn.net/lmmmmmmmmmmmmmmm/article/details/108334009