在屏幕的任何位置显示AlertDialog当我们在android中显示AlertDialog时,它显示在屏幕的中心。有没有办法改变立场?
3 回答
慕雪6442864
TA贡献1812条经验 获得超5个赞
这些答案将移动AlertDialog的位置,但是,显示的对话框的位置还将包括对话框周围的填充。
如果你想摆脱这个填充(例如,将对话框放在屏幕底部),你还需要覆盖styles.xml中的默认AlertDialog样式,将windowBackground设置为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>
以及如接受的答案中所述设置Window.LayoutParameters。
特别向@David Caunt大喊大叫,他的回答是:删除边框,从Dialog填充完成了这张照片。
白板的微信
TA贡献1883条经验 获得超3个赞
为了使设置产生信息效果,我添加了以下代码dialog.getWindow().setAttributes(wmlp);
在gypsicoder的答案中更改了wmlp的值,或者我的测试没有生效wmlp的设置。
- 3 回答
- 0 关注
- 553 浏览
添加回答
举报
0/150
提交
取消