2012-02-09 89 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