Forum Xamarin.Forms

Change Navigation Bar color for Android and IOS in xamarin forms

vinay_inavoluvinay_inavolu SGUniversity ✭✭

Hi

i have a requirement where Navigation pages should have different bar colors for each of the page.

i have a dashboard page and wrote following code when click on listview ltem

NavigationPage newpage= new NavigationPage(new MYInfoPage());
newpage.BarBackgroundColor. = Color.Red;
newpage.BarTextColor = Color.Green;
await Navigation.PushAsync(newpage);

But the color is not getting updated.

Please suggest on this.

regards,
Kumar

Best Answer

  • vinay_inavoluvinay_inavolu SGUniversity ✭✭
    Accepted Answer

    Ok thank you very much colex. Will try this and let you know the outcome.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited May 2019
    1. You have to ensure current page is wrapped in NavigationPage ,so the MainPage set in App should be NavigationPage

    2. Here you should change the current Navigation Color and don't need to create a new Navigation.

      NavigationPage page = App.Current.MainPage as NavigationPage;
      page.BarBackgroundColor = YourColor.
      await Navigation.PushAsync(new MYInfoPage());
      

    Test on iOS and Android .

  • vinay_inavoluvinay_inavolu SGUniversity ✭✭

    Hi

    i am using Master detail page for this implementation. So need to have Navigation page. Adding the above code is showing two navigations bars.. is it possible to set Color without setting Mainpage as Navigation page?

  • ColeXColeX Member, Xamarin Team Xamurai
    edited May 2019

    You mean the root page is Master detail ?

  • vinay_inavoluvinay_inavolu SGUniversity ✭✭

    Yes.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited May 2019

    Okay, the possible workaround i can think

    1. Set x:Name in xaml

      <NavigationPage x:Name="Nav">
      
    2. Change color using Messaging Center.

      ####Master Detailed Page
      MessagingCenter.Subscribe<object> (this, "Hi", (sender) => {
            Nav.BarBackgroundColor = YourColor.
      });
      
      ####MainPageDetail
      MessagingCenter.Send<object> (this, "Hi");
      await Navigation.PushAsync(new MYInfoPage());
      
  • vinay_inavoluvinay_inavolu SGUniversity ✭✭
    Accepted Answer

    Ok thank you very much colex. Will try this and let you know the outcome.

Sign In or Register to comment.