问题描述
我使用Xamarin Forms创建了以下表单.我绘制了一个红色矩形以突出显示问题区域.我需要标题中的蓝色为其他颜色并显示标题.
I have the following form created with Xamarin Forms. I have drawn in a red rectangle to highlight the problem area. I need the blue color in the header to be a different color and show a title.
这就是我要尝试的近似值.请忽略后退箭头,而是忽略汉堡菜单在右侧的事实(顺便说一句,MasterDetail可以在右侧还是左侧使用汉堡包?).
Here is what I am trying to approximate. Please ignore the back arrow and the fact the hamburger menu is on the right (btw, can a MasterDetail have the hamburger on the right vs. left?).
以下代码是我用来创建此代码的代码.我将MainPage(具有ListView)嵌入到NavigationPage中.然后,我将MasterDetailPage的Detail页面设置为上述的NavigationPage.在此处设置BackgroundColor属性不起作用.请注意,Title属性也不起作用.
The following code is what I am using to create this. I am embedding my MainPage (which has the ListView) in a NavigationPage. Then I set the Detail page of a MasterDetailPage to the aforementioned NavigationPage. Setting the BackgroundColor property here isn't working. Notice the Title property isn't working either.
如何更改标题背景的颜色和标题?
How can I change the color and title of the header's background?
var navPage = new NavigationPage(new MainPage());
App.Current.MainPage = new MasterDetailPage
{
BackgroundColor = Color.FromHex("#174873"),
Title = "MY DRIVES",
Master = new MenuPage()
{
Title = "Master Page Title"
},
Detail = navPage
};
推荐答案
设置NavigationPage
的BarBackgroundColor
.您可以执行以下操作(在最基本的示例意义上):
Set the BarBackgroundColor
of the NavigationPage
. You can do something like this (in the most basic example sense):
var nav = new NavigationPage
{
Title = "Detail"
};
nav.PushAsync(new ContentPage() { Title = "Home" });
nav.BarBackgroundColor = Color.MediumPurple;
var mdp = new MasterDetailPage()
{
Master = new ContentPage()
{
Title = "Master"
},
Detail = nav
};
MainPage = mdp;
NavigationPage
所显示的ContentPage
标题就是该栏上的标题.
The title of the ContentPage
being presented by the NavigationPage
is what will show the title on that bar.
这篇关于Xamarin Forms控制标题栏的颜色/标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!