Dark Mode (Theme)
Google has just published the documentation on the dark theme at the end of I/O 2019, here.
To know if the system is currently in dark theme or not, you can implement the following code:
using SA.Android.App;
using SA.Android.Content.Res;
...
// Only supported from android 10.0 (api 29)
if (AN_Build.VERSION.SDK_INT < AN_Build.VERSION_CODES.Q) {
Debug.Log("Not supported")
return;
}
var configuration = AN_MainActivity.Instance.GetResources().GetConfiguration();
var currentNightMode = configuration.UIMode & AN_Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
case AN_Configuration.UI_MODE_NIGHT_NO:
// Night mode is not active, we're using the light theme
Debug.Log("Night mode is not active, we're using the light theme");
break;
case AN_Configuration.UI_MODE_NIGHT_YES:
// Night mode is active, we're using dark theme
Debug.Log("Night mode is active, we're using dark theme");
break;
}
So far it's not possible to implement a callback to be notified whenever the theme changes, but that's not a problem. User can not change the theme while your Unity application is running. So you can choose 2 strategies how you wish to support the dark theme.
- You can check it all the time when the app is resumed, see the OnApplicationPause
- If you do not care much about app theme immediate response (and tbh it will be not super easy to implement immediate skin change) you can only do this check during app launch.
I couldn't get this to work on Android Pie with version 28 of the Android SDK. So I assume that this only works from the next version of the SDK, which will be launched with Q, version 29.
Reliable and high-quality Unity Development service. Let's Talk!
Website | AssetStore | LinkedIn | Youtube | Scripting Reference
- Build Info
- Dark Mode
- Package Info
- Runtime Permissions
- Run External App
- Immersive Mode
- PackageManager
- Popups & Preloaders
- Rate Us Dialog
- Activity
- Intent
- Settings Page
- Media Player
- Date Picker Dialog
- Time Picker Dialog
- Locale
- Wheel Picker Dialog
- Developer Console Setup
- Connecting to The Service
- Purchase Flow
- Transactions Validation
- Subscriptions
- Licensing
- Getting Started
- Games Sing-in
- Server-side API Access
- Leaderboards
- Achievements
- Saved Games
- Image Manager
- Settings Intent