I'm using Androids built in day/night mode functionality and I'd like to add an option to my app for AppCompatDelegate.MODE_NIGHT_AUTO
I'm having a problem though because my app requires certain things to be colored programmatically, and I can't figure out how to check if the app considers itself in night or day mode. Without that, I can't set a flag to choose the right colors.
Calling AppCompatDelegate.getDefaultNightMode()
just returns AppCompatDelegate.MODE_NIGHT_AUTO which is useless.
I don't see anything else that would tell me, but there must be something?
The bitwise operator in Java (which is used in @ephemient 's answer) is different in kotlin so the code might not be easily convertible for beginners. Here is the kotlin version just in case someone needs it:
If you are kotlin developer then you can use below code to judge dark mode.
For more about dark theme mode