Warm tip: This article is reproduced from serverfault.com, please click

Change Color of Day-Shortcuts in Xamarin DatePicker

发布于 2020-11-30 10:43:58

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

Questioner
Einhorni
Viewed
0
Jarvan Zhang - MSFT 2020-11-30 20:35:06

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