2015-04-01 177 views
-1

我有這個alertbox如何在alertBox中設置固定寬度和高度?

alertDialog = new AlertDialog.Builder(Instructions.this); 
     LayoutInflater inflater = this.getLayoutInflater(); 
     View view = inflater.inflate(R.layout.alert_dialog_layout, null); 
     alertDialog.setView(view); 

     final AlertDialog newDialog = alertDialog.create(); 

我嘗試這樣做:

newDialog.getWindow().setLayout(width, height); 

它不工作!

我該怎麼辦?由於

+0

你可以在xml文件本身設置高度和寬度R.layout.alert_dialog_layout – 2015-04-01 11:17:08

+0

我想手動設置它 – pippo15 2015-04-01 12:10:31

回答

0

你必須使用這行:

alertDialog.getWindow().setLayout(width, height); 

alertDialog.close線而不是之前。

希望這會有所幫助。

+0

有一個問題(如果你想我編輯代碼)。我在這個警報對話框中有一個頁腳。使用您的代碼,alertdialog維度變得固定,但如果大於原始大小,頁腳不會在底部對齊,但我有空白區域。我該如何解決它? – pippo15 2015-04-01 18:49:19

+0

如果您的原始問題已解決,請發佈有關新問題的新問題。每個人都能看到這個問題,並會幫助你。如果我的回答對你有幫助,請投票並接受。謝謝。 – Keshav1234 2015-04-02 05:05:14

相關問題