Nurseyit Tursunkulov
Nurseyit Tursunkulov

Reputation: 9380

how to change the status bar color of datepicker?

I have a data picker:

 val builder = MaterialDatePicker.Builder.dateRangePicker()
        val picker = builder.build()
        picker.show(childFragmentManager, picker.toString())

and it's status bar color black:

enter image description here

I want it to be transparent like in fragment which hosts this DataPicker:

enter image description here

how to do it?

Upvotes: 1

Views: 274

Answers (1)

Stoyan Milev
Stoyan Milev

Reputation: 735

After some in-depth research of the theming of the material date picker, I was able to figure it out:

In your activity theme you have to add

<item name="materialCalendarFullscreenTheme">@style/CustomMaterialCalendarFullscreenTheme</item>

And create the theme the following way

<style name="CustomMaterialCalendarFullscreenTheme" parent="ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen">
    <item name="android:windowIsFloating">false</item>
</style>

You could add a custom status bar color by adding this to the CustomMaterialCalendarFullscreenTheme:

<item name="android:statusBarColor">@color/someCoolColor</item>

Note: If you are not interested in what caused the problem you could stop reading here!

The reason is that one of the ancestors of ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen has android:windowIsFloating set to true and if the 'floating' content is very big (as in our case, it is fullscreen) Android decides to change the status bar color to black.

Upvotes: 4

Related Questions