android关于AlertDialog加入EditText无法弹出键盘的问题

     AlertDialog 是 Dialog 的子类,既然子类无法弹出键盘,咱们就用他的父类。

     下面贴出代码供大家参考。


                // 获得要显示的布局                

                View mView = LayoutInflater.from(context).inflate(

R.layout.dialog_input_dialog, null);

                // 创建 dialog

Dialog mAlertDialog = new Dialog(context);

                 // 这一句是取消 dialog 自带的 Title 样式

mAlertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

mAlertDialog.show();

Window window = mAlertDialog.getWindow();

                 // 获取窗口的参数

WindowManager.LayoutParams lp = window.getAttributes();

                // 设置窗口的宽度 ,不设置的话窗口很小的。

lp.width = LayoutParams.MATCH_PARENT;

window.setAttributes(lp);

                // 这一句是 把dialog 的背景设置成 透明色

window.setBackgroundDrawable(new ColorDrawable(0));

window.setContentView(mView);


你可能感兴趣的:(android,dialog,输入,AlertDialog)