I\'m trying to change the background color of navigationBar in navigationPage I\'m using this code`using System;
using System;
using Xamarin.Forms;
using Sys
<Application.Resources>
<ResourceDictionary>
<!--Global Styles-->
<Color x:Key="NavigationPrimary">Green</Color>
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="{StaticResource NavigationPrimary}" />
<Setter Property="BarTextColor" Value="White" />
</Style>
</ResourceDictionary>
</Application.Resources>
If you want to setup a global style in xaml, you could something similar to this:
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Sample.App">
<Application.Resources>
<ResourceDictionary>
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="#ff5733"/>
<Setter Property="BarTextColor" Value="White"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
Just set the BarBackgroundColor property of the NavigationPage instance:
new NavigationPage(new LoginPage()) { BarBackgroundColor = Color.Green };
If you want to change the NavigationBar BackgroundColor on each page with a different color. You can do the following on the Codebehinds of each page/view.
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace NewApp.Cross.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class NewView : ContentPage
{
public NewView()
{
InitializeComponent();
Title = "PageTitle"
NavigationPage.SetHasBackButton(this, false);
((NavigationPage)Application.Current.MainPage).BarBackgroundColor = Color.Black;
((NavigationPage)Application.Current.MainPage).BarTextColor = Color.OrangeRed;
}
}
}
It works on Android and iOS.