Ko0kiE Ko0kiE - 1 month ago 8
Android Question

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!

Answer

EDIT: This works.

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="@android:style/Widget.DeviceDefault.DatePicker">
     <item name="android:textColorPrimary">#FF0000</item> // Red color, for example
</style>

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

Comments