How to Implement dark mode theme in Xamarin.iOS and Xamarin.Android?

Musaab Qamar 1 Reputation point
2021-05-27T17:37:34.957+00:00

I need to implement dark mode for my Xamarin Native (iOS and Android) apps. I did R&D but found most of the material about dark mode implementation for Xamairn Forms only. I could not found any official documentation for Xamarin.iOS or Xamarin.Android regarding dark mode theme implementation. Though this question is not specifically relate to programming issue, but it is somehow programming related issue in some sense, because I am wondering how to start and how it will be implemented for Xamarin Native apps. I will really appreciate any help or document reference in this regard. Thanks

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-05-28T05:59:12.203+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    For Xamarin.Android, you can change your default style from Theme.MaterialComponents.Light.DarkActionBar to Theme.AppCompat.DayNight in styles.xml,

       <style name="AppTheme" parent="Theme.AppCompat.DayNight">  
               <!-- Customize your theme here. -->  
               <item name="colorPrimary">@color/colorPrimary</item>  
               <item name="colorPrimaryDark">@color/colorPrimaryDark</item>  
               <item name="colorAccent">@color/colorAccent</item>  
           </style>  
    

    Then use code in the MainActivity. Your application will be drakMode automatically.

       AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightYes;  
    

    You could refer to the native android's article like this thread(it will work in xamarin.android): developer.android.com/guide/topics/ui/look-and-feel/darktheme

    For iOS, You can refer to this thread to achieve dark mode:

    https://learn.microsoft.com/en-us/xamarin/ios/platform/ios13/dark-mode

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    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.

    0 comments No comments

Your answer

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