Arthurdent510
Arthurdent510

Reputation: 1320

How to set colors for DatePicker dialog in Xamarin?

I'm trying to figure out how to change the background and text colors of the dialog box that shows when you tap a date or time picker. This is in a Xamarin forms project, specifically the android app. Those properties are not exposed anywhere in the DatePicker control or the renderer that I can find... currently it shows up as this bright pink... thanks!

Upvotes: 3

Views: 4713

Answers (1)

Pucho Eric
Pucho Eric

Reputation: 505

Add item : "android:datePickerDialogTheme" in your style.xml

<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>

<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">#2196F3</item>
    </style>

Complete style.xml

    <?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="MyTheme" parent="MyTheme.Base">
    </style>
    <!-- Base theme applied no matter what API -->
    <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
        <item name="windowNoTitle">true</item>
        <!--We will be using the toolbar so no need to show ActionBar-->
        <item name="windowActionBar">false</item>
        <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
        <!-- colorPrimary is used for the default action bar background -->
        <item name="colorPrimary">#2196F3</item>
        <!-- colorPrimaryDark is used for the status bar -->
        <item name="colorPrimaryDark">#2196F3</item>
        <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
        <item name="colorAccent">#2196F3</item>
        <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. -->
        <item name="windowActionModeOverlay">true</item>
        <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
    </style>
    <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">#2196F3</item>
    </style>
    <style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
        <item name="android:headerBackground">#2196F3</item>
    </style>
    <style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
        <item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
    </style>
</resources>

Upvotes: 5

Related Questions