Android: How to change the color of the dateselector in Datepicker widget?

Okay I think I got it.

I tried desperately to find an attribute in MyDatePickerStyle. The solution came to my mind when I rethought the whole inheritance hierarchy. I just had to add the colorAccent to the MyDatePickerDialogTheme.

<style name="MyDatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <!-- this is new -->
    <item name="colorAccent">@color/accent</item>

    <item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
    <item name="android:colorAccent">@color/primDark</item>
</style>

<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
    <item name="android:headerBackground">@color/prim</item>
    <item name="android:calendarTextColor">@color/primDark</item>
    <item name="android:dayOfWeekBackground">@color/primDark</item>
    <item name="android:yearListSelectorColor">@color/accent</item>
    <item name="android:datePickerMode">calendar</item>
    <item name="android:minDate">01/01/2000</item>
</style>

Somehow I thought every theme gets the primary colors from the AppTheme automatically.

So hopefully this will help someone in the future.

Leave a Comment