Java 为什么BottomSheetDialog将状态栏变为黑色?

Java 为什么BottomSheetDialog将状态栏变为黑色?,java,android,bottom-sheet,Java,Android,Bottom Sheet,我已经在我的活动的onCreate()方法中实现了一个底部工作表,如下所示: bottomSheet = new BottomSheetDialog(this); bottomSheet.setContentView(getLayoutInflater().inflate(R.layout.bottom_sheet, null)); bottomSheet.show(); “我的活动”扩展了AppCompatActivity,其中包含TabLayout和ViewPager。。几乎是一个使用材质

我已经在我的活动的
onCreate()
方法中实现了一个底部工作表,如下所示:

bottomSheet = new BottomSheetDialog(this);
bottomSheet.setContentView(getLayoutInflater().inflate(R.layout.bottom_sheet, null));
bottomSheet.show();
“我的活动”扩展了
AppCompatActivity
,其中包含
TabLayout
ViewPager
。。几乎是一个使用材质设计的标准UI

我遇到的问题是,当调用
show()
时,状态栏会立即变黑,给本来平滑的底部纸张展开动画增加了跳跃性,更不用说改变应用程序的配色方案了

我希望状态栏保持与我的主题相关联的默认颜色,并随着底部纸张的展开而平滑变暗

我已经做了相当多的搜索,但没有找到一个具体的解决方案

有什么想法可能导致这种情况,以及我可以采取什么步骤(如果有的话)来修复它吗

黑色状态栏(为了简单起见,删除了UI内容)

首先,创建一个类扩展BottomSheetDialog并重写onCreate(): 然后,设置所有者活动
在styles.xml中添加以下内容:

 <style name="BottomDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="android:windowTranslucentStatus">true</item>
</style>

对于devices>API20,这起到了作用,并使我的状态栏平滑过渡到较暗的色调。希望能有帮助

styles.xml中添加:

<style name="AppTheme" parent="@style/Theme.MaterialComponents.Light.NoActionBar">
    <item name="bottomSheetDialogTheme">@style/BaseBottomSheetDialog</item>
</style>

@“样式/基线”对话框


@可绘制/四舍五入对话框
假的
@样式/底片
@android:彩色/透明
@颜色/原色
 <style name="BottomDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="android:windowTranslucentStatus">true</item>
</style>
bottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomDialogTheme);
<style name="AppTheme" parent="@style/Theme.MaterialComponents.Light.NoActionBar">
    <item name="bottomSheetDialogTheme">@style/BaseBottomSheetDialog</item>
</style>
<style name="BottomSheet" parent="@style/Widget.Design.BottomSheet.Modal">
    <item name="android:background">@drawable/rounded_dialog</item>
</style>

<style name="BaseBottomSheetDialog" parent="@style/Theme.Design.Light.BottomSheetDialog">
    <item name="android:windowIsFloating">false</item>
    <item name="bottomSheetStyle">@style/BottomSheet</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@color/colorPrimary</item>
</style>