1

I am implementing Dark/Light mode in android.

Implementated using below code:

Theme: Theme.MaterialComponents.DayNight.NoActionBar

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)

and

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)

Reference: https://developer.android.com/guide/topics/ui/look-and-feel/darktheme and https://stackoverflow.com/a/61891471/5707364

Its working fine in Emulators with Android 10, 11 and 12 as well as Real device One plus 5T, Oppo oppo f3, etc But it is not working in below device. It always remains in dark theme.

Device model: Redmi 8A Android Version: 10QKQ1.191014001 MIUI Version: MIUI Global 12.5.2 Stable (12.5.2.0(QCPMIXM)) CPU: Octa-core Max 2.01GHz

Activity is recreated, but no effect. check video: https://www.loom.com/share/796ee5029ee14addb9d95514691cd02e

Please help

Mayura Devani
  • 440
  • 3
  • 17
  • This could be related to MIUI OS (any devices that use this OS will suffer this issue). Within `Settings->Display->More Dark Mode Options` make sure you manually turn off your app within the `Individual apps` list. The MIUI OS tries to "force" dark mode to apps that don't have dark theme, however these settings can mess with apps that DO have a dark/light theme. Unfortunately when you install an app it is enabled by default, rather than you having to manually enable. I understand the setting, but its poorly implemented. – Mark Mar 03 '22 at 09:25

0 Answers0