Solve the problem that the EditText cannot pop up the soft keyboard in the Android custom Dialog

Solve the problem that the EditText cannot pop up the soft keyboard in the Android custom Dialog

Problem code

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final Dialog dialog = builder.create();
        builder.setView(View.inflate(this, R.layout.creat_new_function, null));
        dialog.show();
        Window window = dialog.getWindow();
        window.setContentView(R.layout.creat_new_function);

Debug interface

Insert picture description here

Modify the code

        final Dialog dialog = new Dialog(this);
        dialog.setContentView(View.inflate(this, R.layout.creat_new_function, null));
        dialog.show();
        Window window = dialog.getWindow();
        window.setContentView(R.layout.creat_new_function);

Recommission

Insert picture description here

Solution

Due to the limitations of AlertDialog itself, the focus cannot be obtained, so replace AlertDialog in the code with Dialog to solve it.

Guess you like

Origin blog.csdn.net/qq_42790573/article/details/113029781