Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatePickerDialog header background color

I've setup a style for a DatePickerDialog background, and it shows up differently on Nexus 5 (Marshmallow):

enter image description here

The style I'm using is:

<style name="datepicker">
    <item name="android:background">@color/android:white</item>
    <item name="android:textColorPrimaryInverse">@color/android:black</item>
    <item name="android:textColorPrimary">@color/android:black</item>
    <item name="android:textColorSecondary">@color/colorAccent</item>
    <item name="android:textColorSecondaryInverse">@color/colorAccent</item>
    <item name="android:textColorTertiary">@color/android:black</item>
</style>

(colorAccent is gold)

The year at the top is supposed to be controlled by textColorSecondary, but now it's showing up as black. And the background of the header is grey, which I'd like white. What are the names of these items for Marshmallow?

like image 737
MPelletier Avatar asked Sep 05 '17 02:09

MPelletier


1 Answers

You can use this style and theme config for change the text and header color. However, I think it is not more beautiful than default dialog picker.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
    <item name="android:datePickerDialogTheme">@style/MyDatePickerDialogTheme</item>

</style>

<style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
    <item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
    <item name="android:textColorPrimaryInverse">#000</item> <!-- header date, month color && calendar text highlight color -->
    <item name="android:textColorSecondaryInverse">#000</item> <!-- header year color -->

    <item name="android:colorAccent">#B09A60</item> <!-- button color -->
</style>

<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
    <item name="android:headerBackground">#fff</item> <!-- header background color -->
</style>

Tested on API 22, 23, 25 enter image description here

like image 188
Linh Avatar answered Sep 28 '22 07:09

Linh