如何更改导航 Titleview - Xamarin Forms 的背景颜色?

How to change background color of navigation Titleview - Xamarin Forms?

这是我第一次使用导航标题视图。我遇到的问题是 Android 中导航栏的背景与 iOS 中的不同。我想将背景颜色设置为白色,因此 iOS 和 Android 都相同。任何建议如何去做。我在下面包含了代码和图片

XAML代码

    <NavigationPage.TitleView>
    <Label           FontSize="25"
                     TextColor="Black"
                     VerticalOptions="CenterAndExpand"
                     HorizontalOptions="CenterAndExpand"
                     HorizontalTextAlignment="Center"
                     FontFamily="PatrickFont">
                <Label.FormattedText>
                    <FormattedString>
                        <Span Text="Number"/>
                        <Span Text="Generator" TextColor="Red"/>
                    </FormattedString>
                </Label.FormattedText>
            </Label>
</NavigationPage.TitleView>

CS 码

private void InfoIconCommandExecute(object obj)
{
   App.Current.MainPage.Navigation.PushAsync(new InfoPage());
}

选项 1. 在 app.xaml 文件中设置导航页面颜色。这将影响您应用中的所有页面。

...
<Application.Resources>
   <Style TargetType="NavigationPage">
      <Setter Property="BarBackgroundColor" Value="White"/>
      <Setter Property="BarTextColor" Value="OrangeRed" />
   </Style>
</Application.Resources>
...

选项2.在页面文件中设置您要更改导航背景颜色。 YourPage.xaml.cs

...
public YourPage()
{
   InitializeComponent();
   ((NavigationPage)Application.Current.MainPage).BarBackgroundColor = Color.White;
   ((NavigationPage)Application.Current.MainPage).BarTextColor = Color.OrangeRed;
}
...