I need to know if user has enabled dark theme in the OS level so that I can enable dark theme in my app automatically.(not force dark mode)
Asked
Active
Viewed 5,427 times
5
-
1Does this answer your question? [Is there an API to detect which theme the OS is using - dark or light (or other)?](https://stackoverflow.com/questions/55787035/is-there-an-api-to-detect-which-theme-the-os-is-using-dark-or-light-or-other) – Chris Sep 02 '20 at 08:34
-
Just so you know, Android can do this automatically if your app's theme extends one of the `MaterialComponents.DayNight` themes. But check the link above if you want to do it manually. – Gavin Wright Sep 02 '20 at 08:35
1 Answers
13
To detect if the system is in dark theme. Helpful.
switch (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
case Configuration.UI_MODE_NIGHT_YES:
//process
break;
case Configuration.UI_MODE_NIGHT_NO:
// process
break;
}

Arda Kazancı
- 8,341
- 4
- 28
- 50
-
are you calling `getResources().getConfiguration().uiMode` off of the activity context? or application context? – VIN Jul 26 '22 at 21:47
-