2012-02-09 87 views
1

我在设置高度和警告对话框的宽度的问题,下面是我的,我已经写在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); 

请告诉我这里的守则有什么问题。由于

+0

可能重复 [http://stackoverflow.com/questions/4406804/how-to-control-the-width-and-height-of-default-alert-dialog-in-android][1 ] [1]:http://stackoverflow.com/questions/4406804/how-to-control-the-width-and-height-of-default-alert-dialog-in-android – Simon 2012-02-09 07:21:20

回答

3

您需要设置的参数为Height & WidthalertDialog.show();

所以,你需要打电话,

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

调用

alertDialog.show(); 

详细检查this的答案后。

+0

由于很多,你已经解决了我的问题,再次感谢。 – Farhan 2012-02-09 07:38:06

+0

谢谢,节省了我的时间 – 2016-07-26 18:00:07

+0

有道理,但不知何故也没有。无论如何,我希望我在2小时前阅读这个答案!谢谢。 – Loolooii 2016-10-29 23:09:05