While for the most part Uno Platform apps are able to handle theme changes internally, I have some custom code in my app that needs to react to theme change. For example when user changes from light them to dark theme here:
Android display settings for theme
In my code I can get the theme value initially like this:
var color = (Color)App.Current.Resources["SystemBaseHighColor"]
Now when the user changes theme and returns to the app I want to detect that and programmatically update some component. Is there an event I can hook into for this?
You can listen for theme changes on all platforms using the ThemeListener
helper class from the Windows Community Toolkit. It's supported by recent Uno Platform versions.
Just create a new instance of ThemeListener
and subscribe to the ThemeListener.ThemeChanged
event.