-1

My app should do something every time the system theme changes status.

I'm using android studio, maybe Kotlin or Java.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Francesco
  • 1
  • 1
  • https://stackoverflow.com/questions/55787035/is-there-an-api-to-detect-which-theme-the-os-is-using-dark-or-light-or-other – ADM Jul 29 '20 at 08:59
  • Thanks, since android lately (april 2020 I guess) added support for auto switch theme do you know how the system get the time for the theme switch? – Francesco Jul 29 '20 at 09:49
  • See "Be notified of a change in the theme" in linked duplicate – Michael Jul 29 '20 at 11:55

2 Answers2

0

enter image description here

Declare darkmode color in another night color file

king meng
  • 11
  • 2
0

My app should do something every time the system theme changes status

Are you talking about dark theme?

If so, the trick is to use theme attributes instead of specific colors in your layouts and then use a theme that supports dark mode, see above link for more information.

Bram Stoker
  • 1,202
  • 11
  • 14
  • When the system theme changes (dark mode activate/deactivate) the app should do something, so I believe to have the app asleep while the switch does not happen and when it does, the app awake and does what it has to do then goes back asleep, waiting for the next change – Francesco Jul 29 '20 at 10:01
  • Changing to dark theme is a configuration change. Android will recreate all views automatically for you right away, see https://developer.android.com/guide/components/activities/activity-lifecycle#ondestroy – Bram Stoker Jul 29 '20 at 10:06