Share via

Background color change for MAUI DatePicker popup

salilsingh-9961 351 Reputation points
2023-11-28T03:30:48.6633333+00:00

Hi Team,

I am working on a .Net MAUI app (in Visual Studio 2022), Android emulator used is Pixel 5 API 33.

I need to change the background color of DatePicker pop up.

Need to change the top blue color.

User's image

Can you please let me know how to achieve this.

Thanks,

Salil

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

3 answers

Sort by: Most helpful
  1. Всеволод Всеволод 5 Reputation points
    2024-08-15T15:04:42.8666667+00:00

    To change the background color of the DatePicker popup, you need to modify the color in the line:

    <color name="colorAccent">#E3007C</color> 
    

    This line is located in the styles.xml file in the project folder Platforms / Android / Resources / values. The color should be specified in HEX format.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Anonymous
    2023-11-29T05:38:52.84+00:00

    Hello,

    You can do this by creating a custom style and setting it to the android:datePickerDialogTheme.

    Firstly, create a xml file called style.xml in Platforms\Android\Resources\values\ folder.

    Then create a style called MyTheme that extend the Maui.MainTheme and create a style for DatePickerDialog set the top color to other colors.

    <?xml version="1.0" encoding="utf-8" ?>
    
    <resources>
        <style name="MyTheme" parent="Maui.MainTheme">        
            <item name="android:datePickerDialogTheme">@style/CustomDatePickerDialog</item>
        </style>
        <style name="CustomDatePickerDialog" parent="ThemeOverlay.AppCompat.Dialog">
           
            <item name="colorAccent">#ff00ff</item>
        </style>
    
    </resources>
    

    If you want to change color of the selected item and Cancel and Ok button, you need to add following items in theCustomDatePickerDialog style.

       <item name="colorPrimary">#ff00ff</item>
       <item name="colorPrimaryDark">#ff00ff</item>
    

    Next, you need to open the MainAcitivity.cs, set value of Theme to "@style/MyTheme". You need to hide the Actionbar in the Oncreate method as well, if not, you will get two navigationbars.

    [Activity(Theme = "@style/MyTheme".....)]
    public class MainActivity : MauiAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SupportActionBar.Hide();
        }
      
    }
    

    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.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.