Search code examples
xamarincolorsandroid-datepicker

Change Color of Day-Shortcuts in Xamarin DatePicker


Following is what I have guessed so far to manipulate the colors. I couldn't find the name tag for the day-shortcuts marked in the pic below.

  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
  </style>

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#2e0074</item> <!-- FF4081 -->
    <item name="android:background">#292929</item> <!-- Bg-->
    <item name="android:textColor">#ffffff</item> <!-- Header & Ok / Abbrechen -->
    <item name="android:textColorPrimary">#ffffff</item> <!-- Date numbers -->
    
  </style>

enter image description here


Solution

  • Change Color of Day-Shortcuts in Xamarin DatePicker

    To change the color of the weekday in the DatePickerDialog, try adding the android:textColorSecondary item to the <style> tag.

    Check the code:

    styles.xml

    <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
      ...
      <item name="android:textColorSecondary">@color/colorAccent</item>
    </style>
    

    Activity class

    DateTime currently = DateTime.Now;
    DatePickerDialog dialog = new DatePickerDialog(
                                    this,
                                    Resource.Style.AppCompatDialogStyle, 
                                    this,
                                    currently.Year, 
                                    currently.Month - 1, 
                                    currently.Day);
    dialog.Show();
    

    The screenshot:

    enter image description here