Xamarin.Essentials: App Theme
The RequestedTheme API is part of the AppInfo
class and provides information as to what theme is requested for your running app by the system.
Get started
To start using this API, read the getting started guide for Xamarin.Essentials to ensure the library is properly installed and set up in your projects.
Using RequestedTheme
Add a reference to Xamarin.Essentials in your class:
using Xamarin.Essentials;
Obtaining Theme Information
The requested application theme can be detected with the following API:
AppTheme appTheme = AppInfo.RequestedTheme;
This will provide the current requested theme by the system for your application. The return value will be one of the following:
- Unspecified
- Light
- Dark
Unspecified will be returned when the operating system does not have a specific user interface style to request. An example of this is on devices running versions of iOS older than 13.0.
Platform Implementation Specifics
Android uses configuration modes to specify the type of theme to request from the user. Based on the version of Android, it can be changed by the user or is changed when battery saver mode is enabled.
You can read more on the official Android documentation for Dark Theme.