簡體   English   中英

如何設置默認警報對話框的高度和寬度

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

我在設置警報對話框的高度和寬度時遇到問題,以下是我在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);

請告訴我代碼中的問題是什么。 謝謝

您需要在alertDialog.show();之后設置“ HeightWidth的參數alertDialog.show();

所以你需要打電話

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

打電話后

alertDialog.show();

有關更多信息,請查看this答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM