Dialog全屏,去掉状态栏

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31796651/article/details/83147992

dialog即使设置全屏了,但还是有状态栏占用高度这;

直接将下面这行代码放到你的dialog中即可

 @Override
    protected void onStart() {
        super.onStart();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE
                | View.SYSTEM_UI_FLAG_FULLSCREEN;
        this.getWindow().getDecorView().setSystemUiVisibility(uiOptions);
    }

顺便说下自定义dialog宽高:

WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.width = width;
        attributes.height = height;
        getWindow().setAttributes(attributes);

添加两个基本的style

  <!--普通dialog样式-->
    <style name="customerDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:background">@android:color/transparent</item>
        <!-- <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> -->
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowSoftInputMode">stateHidden|adjustPan</item>
    </style>


    <!--透明背景dialog样式-->
    <style name="TransparentDialogStyle" parent="@android:style/Theme.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:backgroundDimEnabled">false</item>
    </style>

猜你喜欢

转载自blog.csdn.net/qq_31796651/article/details/83147992