App use -night drawable when phone is on Dark Mode but app is on light mode

418 Views Asked by At

I have implemented the dark mode using :

when (themePref) {
     ThemeUi.LIGHT -> {
         AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO)
      }
      ThemeUi.DARK -> {
          AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES)
      }
      ThemeUi.AUTO_BEFORE_DARK, ThemeUi.AUTO_BEFORE_LIGHT ->
          AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
      }

which is applied during the creation of the Application class (and when the user want to swipe betwen the mode in the settings of the app).

Everything works fine, except one drawable that continue to follow the phone mode. The first time I start the app, the drawable is taken in the light folder, but if I switch the dark mode on -> off -> on on my phone, and then start the app again, this time the drawable will be black, even if everything else is on light mode.

I don't know if it's linked, but it is one on the only drawable that is in png, in hdpi, mdpi, xhdpi, xxhdpi and xxxhdpi (for both light and dark mode)

drawable dark mode

I can't use SVG for this drawable, I didn't find a solution.

My app theme is Theme.AppCompat.DayNight.DarkActionBar

Note that it doesn't work in the other way either, if my app is in dark mode and the phone on light mode, the drawable will be light.

0

There are 0 best solutions below