<span style="background-color: rgb(255, 255, 255);">AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.show();
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = 200;
params.height = 200 ;
dialog.getWindow().setAttributes(params);
这里需要注意的地方就是,一定要等dialog.show调用了过后,进行设置才会有效果。</span>
void onPrepareDialog(int id, Dialog dialog)中修改Dialog以定制
//布局
dialog.setContentView(R.layout.dialog_warn_net);
//大小
dialog.getWindow().setLayout(dlgWidth, dlgHeight);
//位置
dialog.getWindow().getAttributes().x = mDialogLayoutParamsX;
dialog.getWindow().getAttributes().y = mDialogLayoutParamsY;
自定义AlertDialog尺寸位置
本文介绍如何使用Android中的AlertDialog.Builder创建对话框,并自定义其布局、尺寸及显示位置。通过设置ContentView来改变对话框的内容视图,利用getWindow().setLayout()调整宽度和高度,最后通过getAttributes().x和getAttributes().y设定对话框的水平和垂直位置。
2410

被折叠的 条评论
为什么被折叠?



