在屏幕的任何位置顯示AlertDialog當(dāng)我們在android中顯示AlertDialog時,它顯示在屏幕的中心。有沒有辦法改變立場?
3 回答

慕雪6442864
TA貢獻(xiàn)1812條經(jīng)驗 獲得超5個贊
這些答案將移動AlertDialog的位置,但是,顯示的對話框的位置還將包括對話框周圍的填充。
如果你想擺脫這個填充(例如,將對話框放在屏幕底部),你還需要覆蓋styles.xml中的默認(rèn)AlertDialog樣式,將windowBackground設(shè)置為null,就像這樣:
<resources> <!-- Example app theme - mine uses the below --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:alertDialogTheme">@style/MyDialogTheme</item> </style> <style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> <!-- Full width --> <item name="android:layout_width">fill_parent</item> <!-- Null window background kills surrounding padding --> <item name="android:windowBackground">@null</item> <item name="android:windowNoTitle">true</item> </style></resources>
以及如接受的答案中所述設(shè)置Window.LayoutParameters。
特別向@David Caunt大喊大叫,他的回答是:刪除邊框,從Dialog填充完成了這張照片。

白板的微信
TA貢獻(xiàn)1883條經(jīng)驗 獲得超3個贊
為了使設(shè)置產(chǎn)生信息效果,我添加了以下代碼dialog.getWindow().setAttributes(wmlp);
在gypsicoder的答案中更改了wmlp的值,或者我的測試沒有生效wmlp的設(shè)置。
- 3 回答
- 0 關(guān)注
- 574 瀏覽
添加回答
舉報
0/150
提交
取消