Search code examples
xamarinxamarin.formsbackground-colormaster-detail

Xamarin Forms: How to change the background color of the Master Detail content page?


I have a master-detail page in my project and added some content pages into it as the children. How I can change the color of the top bar of the child content page? I have added some icons on the top bar using <NavigationPage.TitleView>.

I need to change the red square background color. Already I tried the solution preferred here, but that not solves my problem.


Solution

  • In order to change that Navigation bar's background color for Android follow the following steps:

    Go to your Android Project -> Resources -> values -> styles.xml
    

    Open style.xaml file update colorPrimary value with your required hex color code

    <!-- colorPrimary is used for the default action bar background -->
        <item name="colorPrimary">#3478c9</item>
    

    For iOS this can be controlled from App.xaml file, no need to write anything in iOS project

    <Application.Resources>
        <ResourceDictionary>
    
          <!-- Styles -->
          <Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor" Value="#3478c9"/>
            <Setter Property="BarTextColor" Value="White"/>
          </Style>
          <!-- Styles -->
    
        </ResourceDictionary>
      </Application.Resources>