Search code examples
javaandroiddatepickertextcolor

Change fontcolor of DatePicker Android


I am trying to change the font color of the datepicker, I already have been searching but i wasn't able to get a precise answer. Could you please help me? My layout is like this:

<DatePicker
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/datePicker"
    android:calendarViewShown="false"
    android:spinnersShown="true"
    android:datePickerMode="spinner"
    android:layout_below="@+id/tb_register_last_name"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignRight="@+id/bt_register_tostep3"
    android:layout_alignEnd="@+id/bt_register_tostep3"
    style="@style/MyDatePicker"/>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:datePickerStyle">@style/MyDatePicker</item>

</style>


<style name="MyDatePicker" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorPrimary">**@color/CorProfilePi**c</item>
    <item name="colorPrimaryDark">**@color/CorProfilePic**</item>
    <item name="colorAccent">**@color/CorProfilePic**</item>


</style>

Colors.xml:

<resources>
<color name="colorPrimary">#479dcc</color>
<color name="colorPrimaryDark">#146ba6</color>
<color name="colorAccent">#0a8da0</color>
<color name="CorProfilePic">#ffffff</color>

What am i doing wrong? Thanks! (i'm new at android development) Thanks!


Solution

  • EDIT2: This works. (Added divider color)

    Your XML

    <DatePicker
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/datePicker"
         android:calendarViewShown="false"
         android:spinnersShown="true"
         android:datePickerMode="spinner"
         android:layout_below="@+id/tb_register_last_name"
         android:layout_alignParentLeft="true"
         android:layout_alignParentStart="true"
         android:layout_alignRight="@+id/bt_register_tostep3"
         android:layout_alignEnd="@+id/bt_register_tostep3"
         android:theme="@style/MyDatePicker"/>
    

    In styles.xml, set this (copy-paste the code)

    <style name="MyDatePicker" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorControlNormal">#00FF00</item>
        <item name="colorControlActivated">#00FF00</item>
        <item name="android:textColorPrimary">#FF0000</item>
    </style>
    

    Google materialdoc will be helpful for you in the future.

    Change your style and let me know if it works!!