I implemented the dark theme using DayNight material themes in my app. I followed several articles and conference talks on the internet. Everything worked well until some small things started to occur. Let me explain:
The app has several activities. In order to not theme every activity explicitly, I followed advice to put the initial theme setting in my Application's onCreate() method. This has one drawback though, which I will explain next.
1.) AppCompat implements night mode at the activity level, which means that it won't update the application context (which I am using to set the theme app wide) (source: https://issuetracker.google.com/issues/134379747)
2.) The following piece of code is recommended to check whether or not the app is running in which mode. But it returns exactly the opposite mode in my case:
val currentNightMode = configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
when (currentNightMode) {
Configuration.UI_MODE_NIGHT_NO -> {} // Night mode is not active, we're using the light theme
Configuration.UI_MODE_NIGHT_YES -> {} // Night mode is active, we're using dark theme
}
3.) When setting my app to follow system and then I manually switch to light mode (in the app) and then come back to follow system, my app stays light even tho my phone is in system-wide dark theme. It does change however when toggling my app's theme.
What am I doing wrong? Could a possible solution be to set the theme on an activity level?