如何解决如何更改导航标题视图的背景颜色 - 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;
}
...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。