I am using AlertDialog.Builder in order to create an input box, with EditText as the input method.
Unfortunately, the Soft Keyboard doesn\'t pop, al
This problem occurs when EditText is added after AlertDialog.onCreate is called.
https://developer.android.com/reference/androidx/appcompat/app/AlertDialog.Builder
The AlertDialog class takes care of automatically setting android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM for you based on whether any views in the dialog return true from View.onCheckIsTextEditor().
You need to clear the FLAG_ALT_FOCUSABLE_IM flag.
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Because AlertDialog.show is called in the DialogFragment.onStart, you can insert the code in the DialogFragment.onStart.
@Override
public void onStart() {
super.onStart();
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
}
Or you can use the Dialog.setOnShowListener if you do not use a DialogFragment.
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
}
});