主详细信息页面信息
在我们回答这个问题之前,我们先回顾一下MasterDetailPage
类以及如何MasterDetailPage
在您的示例中进行了配置。
The MasterDetailPage
Xamarin.Forms 中的类需要两个Page
特性:
The Detail
您的示例中的页面位于屏幕的右侧。这Detail
页面是一个ContentPage
里面的一个NavigationPage
with NavigationPage.BarBackgroundColor
set to Color.Black
. The ContentPage
在这里面NavigationPage
has ContentPage.BackgroundColor
set to Color.Grey
.
The Master
您的示例中的页面位于屏幕的左侧。它是一个ContentPage
其中包含一个ListView
。在不知道你的代码的情况下,我的猜测是ContentPage.BackgroundColor
被设定为Color.White
以及ListView.BackgroundColor
未设置。
当您选择导航抽屉图标时,导航栏将被覆盖。发生这种情况是因为导航栏位于Detail
页面,而不是在Master
page.
回答你的问题
为什么导航栏颜色不显示在Master
page?
The Master
页面只能是一个ContentPage
并且它不能位于NavigationPage
,因此它没有导航栏(只有一个NavigationPage
可以有一个导航栏)。
如何改进用户界面?
首先,验证您使用的是最新版本的 Xamarin.Forms v2.3.2.127。
iOS
在 iOS 上,您可以模仿Detail
通过设置页面的导航栏颜色Padding
的财产Master
页面并设置Master
page BackgroundColor
财产给Color.Black
像这样:
Master = new ContentPage
{
BackgroundColor = Color.Black,
Padding = new Thickness(0, Device.OnPlatform(64, 0, 0), 0, 0)
};
Android
在 Android 上,预期的行为是Master
页面从左侧滑入并覆盖Detail
页。要更新 Android UI,我建议更新以下三个项目之一:Master.BackgroundColor
财产,ListView.BackgroundColor
属性或 ListView 中使用的图标的颜色Master
page.
如果您不希望导航栏向右移动,您可以扩展FormsApplicationActivity
在安卓中MainActivity
类,这将阻止导航栏移动:
public class MainActivity : Xamarin.Forms.Platform.Android.FormsApplicationActivity
此示例显示,当您使用时,导航栏不会在 Android 应用程序上滑动FormsApplicationActivity
:
https://developer.xamarin.com/samples/xamarin-forms/Navigation/MasterDetailPage/ https://developer.xamarin.com/samples/xamarin-forms/Navigation/MasterDetailPage/