Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Dynamically change system bar color

$
0
0

Hello,

I am trying to change system bar color according to some property of the View that is currently opened so that it matches NavigationBar color. I am changing NavigationBar color in OnAppearing overriden method in view's backing code by setting dynamic resource value:

in App.xaml



...

and in OnAppearing:
Application.Current.Resources["NavigationBarColor"] = selectedColor;

However, there is no way to use this approach for changing system bar color. I got it to work for iOS by adding the following to Info.plist file:

UIStatusBarStyle
UIStatusBarStyleLightContent
UIViewControllerBasedStatusBarAppearance

But no luck for Android part still. The furthest I got is to use CustomRenderer for base page and override OnElementPropertyChanged event in it so that I could monitor if my property of interest is changed and change StatusBar color accordingly:

_window.SetStatusBarColor(((BaseContentPage)Element).StatusBarColor.ToAndroid());

However, if I use back button to go to page that should have different color, the renderer will not be attached to the window (since the page was already present in the Navigation stack) and the color does not get changed.

Please help, I have been banging my head off the wall for days now.


Viewing all articles
Browse latest Browse all 91519

Trending Articles