Quantcast
Viewing all articles
Browse latest Browse all 91519

Force Change of android:textColor at runtime

I have the a TabbedPage Application and want to change the textcolor at runtime.

<Label Text="Color change works for this label, as i set textcolor" TextColor="{DynamicResource MyTextColor}"/>
<Label Text="but i want to have it work for all labels and other elements without DynamicResource=MyTextColor"/>

public partial class TabPage : ContentPage
protected override void OnAppearing()
{
    // this works
    Resources["MyTextColor"] = DarkTheme ? Color.Red : Color.Blue;

    // this does not work at runtime, textcolor defined in styles <item name="android:textColor">#43d5e6</item> does not update at runtime
    SetTheme(DarkTheme ? Resource.Style.MainTheme_Dark: Resource.Style.MainTheme_Light);
}

item name="android:textColor> is differently defined in MainTheme_Dark and MainTheme_Light and gets at once applied to new Pages (for example Navigation.PushModalAsync(new NavigationPage(new NewPage())), but it gets not applied to existing TabPage. I have to close my app and only afterwards, it correctly applies the new "item name=android:textColor> from the selected MainTheme.

How can I force to change android:textColor at runtime in the OnAppearing()-event?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>