0

I want to get the current theme of the app and I am doing it as shown below,

when (this.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)) {
        Configuration.UI_MODE_NIGHT_YES -> onThemeChange(Themes.DARK)
        Configuration.UI_MODE_NIGHT_NO -> onThemeChange(Themes.LIGHT)
    }

I have added this in my application class, so on every app launch, the app will detect the current theme and apply it.

But how do I listen to the system theme change at run time.

Got this reference, but I don't want to do it at activity level, rather want to do it at application level.

Please do let me know, what's the best possible way to detect the system theme changes at runtime in android.

hasan_shaikh
  • 1,434
  • 1
  • 15
  • 38

0 Answers0