If want to modify color of navigation bar dynamically , you can define color
key of navigation bar in App.xaml as follow :(Also can add some default color
key here)
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="AppZXing.App">
<Application.Resources>
<!-- Application resource dictionary -->
<ResourceDictionary>
<Color x:Key="navbarredcolor">#FFFFFF</Color>
<!--White color -->
<Color x:Key="navbarwhitecolor">#191919</Color>
<!--Black color -->
<Style ApplyToDerivedTypes="true"
TargetType="NavigationPage">
<!--ApplyToDerivedTypes means for all content pages -->
<Setter Property="BarBackgroundColor"
Value="{DynamicResource Key=navbarcolor}" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
Then modify in changeBackground
method :
App.Current.Resources["navbarcolor"] = Color.Red;
If defined color key in App.xaml , also can do as follow :
App.Current.Resources["navbarcolor"] = App.Current.Resources["navbarredcolor"];