解决Android自定义AlertDialog中EditText无法弹出软键盘的问题

解决Android自定义AlertDialog中EditText无法弹出软键盘的问题

问题代码

        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);

调试界面


修改代码

        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);

重新调试

解决方法

因AlertDialog本身有限制,无法获得焦点,所以将代码中的AlertDialog替换为Dialog即可解决。

————————————————
原文链接:https://blog.csdn.net/qq_42790573/article/details/113029781

猜你喜欢

转载自blog.csdn.net/weixin_42602900/article/details/132906773