Why does BottomSheetDialog turn the status bar black?
I implemented a Bottom Sheet in the onCreate()
method of the activity as follows:
bottomSheet = new BottomSheetDialog(this);
bottomSheet.setContentView(getLayoutInflater().inflate(R.layout.bottom_sheet, null));
bottomSheet.show();
My activity extends the AppCompat activity
and has a TabLayout
and ViewPager
: almost a standard UI using Material Design.
The problem I’m having is that when show()
is called, the status bar immediately goes black, adding a flutter to the otherwise smooth Bottom Sheet single-unfold animation, not to mention changing the app’s color scheme.
I want the status bar to remain the default color associated with my theme and smoothly darken as the Bottom Sheet unfolds.
I’ve done a lot of searching but haven’t been able to find a concrete solution.
Any ideas that might be causing this issue and what steps, if any, I can take to fix it?
Black status bar (UI content removed for simplicity)
Solution
Add the following to your styles.xml:
<style name="BottomDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowTranslucentStatus">true</item>
</style>
Then you can add it to your dialog box:
bottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomDialogTheme);
For devices > API 20 This works and smoothly transitions to the darker shadows of my status bar. Hope that helps.