【发布时间】:2019-10-17 18:40:32
【问题描述】:
我正在尝试为一个简单的 XF 应用程序设置 BarBackgroundColor 和 BarTextColor,但我不理解输出。代码后面是我看到的图片,所有代码都可以下载here。
我在下面设置了 BarBackgroundColor、BarTextColor 和 BackgroundColor。似乎唯一设置的颜色(来自所附图像)是 Color.Blue BarBackgroundColor。导航栏和状态栏的文字不应该是白色的吗?为什么页面的其余部分不是红色的?
App.xaml.cs
public App()
{
InitializeComponent();
var navPage = new NavigationPage(new MainPage());
navPage.BarBackgroundColor = Color.Blue;
navPage.BarTextColor = Color.White;
navPage.BackgroundColor = Color.Red;
MainPage = navPage;
}
XAML
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="SampleApp.MainPage">
<NavigationPage.TitleView>
<StackLayout HorizontalOptions="Center"
VerticalOptions="Center">
<Label Text="Page Title" />
</StackLayout>
</NavigationPage.TitleView>
<StackLayout>
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
这是我得到的输出。
【问题讨论】:
-
C# sn-p 中的属性指的是标准导航标题视图。当您像在 XAML 中一样提供自定义 TitleView 时,您可以自己控制所有 UI。
-
谢谢。上面的状态/运营商栏呢?
-
在当前版本 afaik 中,iOS 中没有“状态栏”。状态栏是导航栏的一部分,如果有的话,它是整个视图的一部分。您需要设置填充以在状态行之外启动视图
标签: xamarin xamarin.forms xamarin.ios