How to Check For Dark Mode in Xamarin.Forms

后端 未结 3 1876
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 05:56

Now that iOS 13 and Android Q allow the user to enable Dark Mode at the operating system level, how can I check for it in Xamarin.Forms?

I\'ve created this in my Xam

3条回答
  •  佛祖请我去吃肉
    2020-12-17 06:36

    UPDATE as of April 2020:

    It is no longer necessary to use platform-specific services to check for light/dark mode in Xamarin.Forms.

    We can now get the current theme directly via:

    OSAppTheme currentTheme = Application.Current.RequestedTheme;
    

    where the RequestedTheme property returns an OSAppTheme enumeration member: Unspecified, Dark, or Light.

    For more info: see documentation and the updated Xamarin.Forms Application.cs code.

提交回复
热议问题