3

I am trying to change the text color of my DatePicker

 <DatePicker
            android:id="@+id/start_date_text"
            android:layout_width="400dp"
            android:layout_height="190dp"
            android:datePickerMode="spinner"
            android:calendarViewShown="false"
            style="@style/MyDatePicker" />

This code just gives 3 pickers, month, day and year. How can I change this text color?

 <style name="MyDatePicker" parent="android:Widget.Material.Light.DatePicker">
    <item name="android:textColor">@color/Black</item>
</style>

where Widget.Material.Light.DatePicker has been all the DatePicker options under Widget

Jordan Carlyon
  • 33
  • 1
  • 1
  • 4
  • For a DatePickerDialog check my answer on **Change DatePicker header text color** http://stackoverflow.com/a/42460022/5188159 – Charuක Feb 26 '17 at 03:28

2 Answers2

17

As with most components, the DatePicker's text color is effected by textColorPrimary:

<item name="android:textColorPrimary">@color/Black</item>
tachyonflux
  • 19,305
  • 6
  • 43
  • 65
  • 2
    This doesn't change the color of the text. – Jordan Carlyon Jul 10 '15 at 14:30
  • 3
    It only works if it is in your main app theme. It's somewhat difficult to change the font color directly because it is buried under several layout and ultimately the `EditText` itself will be styled as `?android:attr/textAppearanceMedium` which essentially only will refer to the `textColorPrimary` in your main theme. This question might help: http://stackoverflow.com/questions/22962075/change-the-text-color-of-numberpicker. If you want to change it for a `DatePicker`, it would require another outer loop to go though the `DatePicker`'s children to find the `NumberPicker`s. – tachyonflux Jul 10 '15 at 16:42
  • Thanks, that is a very involved process to change something so simple. My app can get by with just using a consistent color throughout though. – Jordan Carlyon Jul 10 '15 at 19:35
  • adding this to the base app theme did the trick, Thanks! one note : this does only change numbers color, but not days letters in the top to change days letters as well you should override android:textColorSecondary. Happy coding ! – Tamim Attafi May 18 '19 at 14:55
1

I don't know what your style have but you can do it this way:

<style name="MyDatePicker" parent="@android:style/Widget.DeviceDefault.DatePicker">

  <item name="android:textColor">#FF0000</item>

</style>
Jorge Casariego
  • 20,634
  • 6
  • 84
  • 96