Access AppThemeBinding in App.xaml from Android RRS feed

  • Question

  • User393906 posted

    I'm using AppThemeBinding to respond to the dark theme on a device. I put all the colors in App.xaml and then I using static resource to access the style:

    Now I need to access these colors from Android and iOS in two different ways:

    1) With xml:

    2) With C#:

    Is this possible? If yes, how? If now, how can I achieve the respond to dark/light theme in Android and iOS?

    I hope someone can help.

    Tuesday, September 29, 2020 8:36 PM

All replies

  • User129559 posted

    The App class has an event for theme changed that you can listen to in the Android or iOS layer, and then respond by pulling either the light or dark resource depending. That way you dont have to worry about the AppThemeBinding.

    You can't put it into the layer list, you will have to create that list in code and import it correctly or have a light and dark colors xml files in the native manner.

    Tuesday, September 29, 2020 9:08 PM
  • User393906 posted

    Hi @AdamMeaney

    Thanks for the quick response.

    If I create dark and light colors xml files, how can I respond to the correct file depending on system theme?

    Tuesday, September 29, 2020 9:11 PM
  • User129559 posted

    This is a reasonable example project that shows how to have dark resources and light resources.

    Then all you need is to have a style based on DayNight in your styles.xml (also in the example project).

    Here is the android blog it comes from.

    Tuesday, September 29, 2020 9:26 PM