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?
Use the system setting (Settings -> Display -> Theme) to enable Dark theme. Use the Quick Settings tile to switch themes from the notification tray (once enabled). On Pixel devices, selecting the Battery Saver mode enables Dark theme at the same time.
Disable all over the app: AppCompatDelegate. setDefaultNightMode(AppCompatDelegate. MODE_NIGHT_NO)
On Android, click your profile image in the top left, then click settings and privacy > display and Sound, and toggle on dark mode. Gmail: Go to settings > general settings > theme. Then choose light, dark or system default.
If you want to disable Force Dark for specific views, you can do so by adding a android:forceDarkAllowed attribute to the view in the XML. You can also use setForceDarkAllowed() to do so programmatically.
int nightModeFlags = getContext().getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; switch (nightModeFlags) { case Configuration.UI_MODE_NIGHT_YES: doStuff(); break; case Configuration.UI_MODE_NIGHT_NO: doStuff(); break; case Configuration.UI_MODE_NIGHT_UNDEFINED: doStuff(); break; }
If you are kotlin developer then you can use below code to judge dark mode.
when (context.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)) { Configuration.UI_MODE_NIGHT_YES -> {} Configuration.UI_MODE_NIGHT_NO -> {} Configuration.UI_MODE_NIGHT_UNDEFINED -> {} }
For more about dark theme mode
https://github.com/android/user-interface-samples/tree/main/DarkTheme
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With