场景:
在项目中,使用AlertDialog创建了一个自定义的Dialog,但是运行之后却只显示一小长方块的空白视图,解决方法如下
//传入一个Activity类型的上下文context
final AlertDialog dialog = new AlertDialog.Builder(context).create();
View itemRenameDialogView = View.inflate(context, R.layout.scanpay_dialog_screen_time_out_custom, null);
//Todo 一定要先show在senContentView
dialog.show();
dialog.setContentView(itemRenameDialogView);
//系统默认隐藏了软件键盘,清除标志使可以弹出键盘
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
//设置布局宽高
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, 1000);