Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change backGround color in Xamarin forms NavigationPage

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 System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
namespace P
{
public class App : Application
{
    public App ()
    {
 MainPage = new NavigationPage(new LoginPage());
    }
    protected override void OnStart ()
    {
    }
    protected override void OnSleep ()
    {
    }
    protected override void OnResume ()
    {
        // Handle when your app resumes
    }
   }
  }

how can I do it?

like image 811
Shimon Wiener Avatar asked Feb 20 '15 14:02

Shimon Wiener


2 Answers

Just set the BarBackgroundColor property of the NavigationPage instance:

new NavigationPage(new LoginPage()) { BarBackgroundColor = Color.Green };
like image 78
Andy Hopper Avatar answered Sep 27 '22 23:09

Andy Hopper


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>
like image 28
Jahmic Avatar answered Sep 27 '22 23:09

Jahmic