如何在自定义对话框中使状态栏处于非活动状态

问题描述

嘿,我想让我的状态栏处于非活动状态,请查看图像,它上面有阴影或其他东西。这是我的BottomSheetDialogFragment

enter image description here

当我在 BottomSheetDialogFragment 类中打开我的自定义对话框时,状态栏颜色变为白色。

enter image description here

我有自定义对话框类的代码

class CustomDialog(
    context: Context,) : Dialog(context) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val screenWidth = (displayMetrics(context).widthPixels * 0.8).toInt()
        setContentView(R.layout.dialog_layout)
        window?.setLayout(screenWidth,ViewGroup.LayoutParams.WRAP_CONTENT)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
    }
}

有人知道如何使状态栏处于非活动状态吗? 提前致谢。

解决方法

您必须添加底片的样式。

<style name="AppModalStyle" parent="Widget.Design.BottomSheet.Modal">
    <item name="android:background">@drawable/rounded_dialog</item>
</style>

<style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/AppModalStyle</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowSoftInputMode">adjustResize</item>
</style>

最后添加这个样式:

  <style name="Theme.MyApp" parent="Base.Theme.MyApp">
            <item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
    </style>