In my Xamarin app, I set the color of Navigation Bar (Status bar / top bar) in styles.xml page. And the color of navigation bar in all page changes to White.
styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#FFFFFF</item>
</style>
</resources>
Now, I just want to change the color of navigation bar in single content page to Black.
I followed this answer by pasting the code in the content page, but color didn't change.
((NavigationPage)Application.Current.MainPage).BarBackgroundColor = Color.Black;
((NavigationPage)Application.Current.MainPage).BarTextColor = Color.Black;
UPDATE
Try this,
In App.xaml for all pages
<Application.Resources>
<ResourceDictionary>
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="White"/>
<Setter Property="BarTextColor" Value="Black" />
</Style>
</ResourceDictionary>
</Application.Resources>
In lets say Page 2 with Color Black , and with OnDisappearing White again for all
public partial class Page2 : ContentPage
{
public Page2()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
var navigationPage = Application.Current.MainPage as NavigationPage;
navigationPage.BarBackgroundColor = Color.Black;
}
private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new Page2DetailsPage());
}
protected override void OnDisappearing()
{
base.OnDisappearing();
var navigationPage = Application.Current.MainPage as NavigationPage;
navigationPage.BarBackgroundColor = Color.White;
}