繁体   English   中英

如何更改导航 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>

客户服务代码

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;
}
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM