首页 > 解决方案 > Xamarin Forms:如何更改 Master Detail 内容页面的背景颜色?

问题描述

我的项目中有一个主详细信息页面,并在其中添加了一些内容页面作为子项。如何更改子内容页面顶部栏的颜色?我在顶部栏上添加了一些图标,使用<NavigationPage.TitleView>.

我需要更改红色方形背景颜色。我已经尝试过这里首选的解决方案,但这并不能解决我的问题。

标签: xamarinxamarin.formsbackground-colormaster-detail

解决方案


要更改Android导航栏的背景颜色,请执行以下步骤:

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

colorPrimary使用所需的十六进制颜色代码打开 style.xaml 文件更新值

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

对于iOS,这可以通过 App.xaml 文件进行控制,无需在 iOS 项目中编写任何内容

<Application.Resources>
    <ResourceDictionary>

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

    </ResourceDictionary>
  </Application.Resources>

推荐阅读