Change title and selected date colors in Android datepicker popup

Jeff Pfahl 91 Reputation points
2022-10-13T16:19:18.637+00:00

How do I set the background color the title of the datepicker popup in android to my app primary color. also like to change the selected date color.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,961 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 69,311 Reputation points Microsoft Vendor
    2022-10-14T06:47:58.223+00:00

    Hello,

    How do I set the background color the title of the datepicker popup in android to my app primary color. also like to change the selected date color

    You can create a styles.xml, add custom android:datePickerDialogTheme in it like following code. I add all of properties that can be changed in native android datePicker. You can choose some of them that you want.

       <?xml version="1.0" encoding="utf-8" ?>  
       <resources>  
           <style name="MyTheme" parent="MainTheme.Base">  
               <item name="android:datePickerDialogTheme">@style/CustomDatePickerDialog</item>  
           </style>  
         
          <style name="CustomDatePickerDialog" parent="ThemeOverlay.AppCompat.Dialog">  
                 <!--header background-->  
                 <item name="colorAccent">#009933</item>  
                 <!--header textcolor-->  
                 <item name="android:textColorPrimaryInverse">#ff9900</item>  
                 <!--body background-->  
                 <item name="android:windowBackground">#000099</item>  
                 <!--selected day-->  
                 <item name="android:colorControlActivated">#ff8000</item>  
                 <!--days of the month-->  
                 <item name="android:textColorPrimary">#ffff00</item>  
                 <!--days of the week-->  
                 <item name="android:textColorSecondary">#ff0066</item>  
                 <!--cancel&ok-->  
                 <item name="android:textColor">#00ffff</item>  
            </style>  
       </resources>  
    

    Then, you can set this Theme to your MainActivity. But this action will affect MAUI splash screen in android, if you want to use splash screen, you can refer to this document: splash-screen to create a new one.

       [Activity(Theme = "@style/MyTheme", ....)]  
       public class MainActivity : MauiAppCompatActivity  
       {  
       }  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.