简体   繁体   English

如何设置默认警报对话框的高度和宽度

[英]How to set the height and width of the Default Alert Dialog

I have a problem in setting the height and width of an Alert Dialog, below is my Code that i have written in OnCreateDialog() method: 我在设置警报对话框的高度和宽度时遇到问题,以下是我在OnCreateDialog()方法中编写的代码:

AlertDialog dialog = new AlertDialog.Builder(context ,AlertDialog.THEME_HOLO_LIGHT)
    .setTitle("Title")        
    .setAdapter(adapter, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

            switch(which){

            case 0:
                //some Code
            break;
            case 1:                 
                //some Code
            break;
            }

        }
    })
    .create();


WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();


WMLP.x = 80;   //x position
WMLP.y = -100;   //y position
WMLP.height = 100;
WMLP.width = 100;

dialog.getWindow().setAttributes(WMLP);
     //OR
dialog.getWindow().setLayout(100, 100);

Kindly tell me what is the problem here in the Code. 请告诉我代码中的问题是什么。 Thanks 谢谢

You need to set the parameters for Height & Width after alertDialog.show(); 您需要在alertDialog.show();之后设置“ HeightWidth的参数alertDialog.show();

So you need to call, 所以你需要打电话

alertDialog.getWindow().setLayout(100, 100);

After calling 打电话后

alertDialog.show();

For more check this answer. 有关更多信息,请查看this答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM