How to make an Alert dialog in full screen in Andr

2019-04-06 18:43发布

How to make an Alert Dialog in full screen in Android?

3条回答
霸刀☆藐视天下
2楼-- · 2019-04-06 18:53

if you're using DialogFragment to build AlertDialog you may set MATCH_PARENT on LayoutParams in onResume():

@Override
public void onResume() {
    super.onResume();
    ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
    params.width = WindowManager.LayoutParams.MATCH_PARENT;
    params.height = WindowManager.LayoutParams.MATCH_PARENT;
    getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
}
查看更多
在下西门庆
3楼-- · 2019-04-06 19:05

Try below code

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
查看更多
别忘想泡老子
4楼-- · 2019-04-06 19:15

you must create a custom style for your dialog

in your style.xml

 <style name="DialogTheme" parent="android:Theme.Dialog">

    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">fill_parent</item>   
    <!-- No backgrounds, titles or window float -->
    <item name="android:windowBackground">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
</style>

while inflating your dialog set this theme

dialog = new Dialog(this, R.style.DialogTheme);

查看更多
登录 后发表回答