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 2,447 times
2
-
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
8
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ı
- 3,877
- 2
- 16
- 33