3

I want to customize the DatePicker provided by Android. Here is a very good answer explaning how to achieve this. I followed it, but it is not working as expected.

This is the default date picker that comes with Android

enter image description here

I am able to change the header background header using the following code.

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:datePickerDialogTheme">@style/MyDatePickerDialogTheme</item>
    </style>

    <style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
        <item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
    </style>

    <style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
        <item name="android:headerBackground">#ff0000</item>
    </style>
</resources>

Which results in the following dialog

enter image description here

But I want to change the text appearance of the year field. I tried the following code for this.

 <style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
    <item name="android:headerBackground">#ff0000</item>
    <item name="android:headerYearTextAppearance">@style/headerYearTextAppearance</item>
</style>

<style name="headerYearTextAppearance" parent="TextAppearance.AppCompat">
    <item name="android:textSize">22dp</item>
    <item name="android:textColor">#000000</item>
</style>

But, I am not able to change the textColor or size of the year field in the dialog. Any other attribute other than the header background is not working. Any idea or working example of how to achieve this.

Community
  • 1
  • 1
thedarkpassenger
  • 7,158
  • 3
  • 37
  • 61

0 Answers0