简体   繁体   English

如何使用Xamarin.Forms更改标题中字体的颜色?

[英]How can I change the color of the font in the Title with Xamarin.Forms?

I am setting a title like this: 我正在设置这样的标题:

 Title = "Card " + index;

and then later in my code I increment index and set it once more: 然后在我的代码中稍后增加索引并再次设置它:

 Title = "Card " + index;

Is there a way that I can change the color of the title to Gray that will work in both iOS and Android? 有没有一种方法可以将标题的颜色更改为同时适用于iOS和Android的灰色?

Xamarin Forms Way: Xamarin形成方式:

You can use the NavigationPage.BarTextColor for this. 您可以为此使用NavigationPage.BarTextColor Set this property when you initially create the NavigationPage . 最初创建NavigationPage时,请设置此属性。

iOS Way: iOS方式:

You can also add the following to the your AppDelegate to change the bar text color globally for the iOS side (I usually put them between the Forms.Init() and LoadApplication() lines: 您还可以将以下内容添加到AppDelegate中,以全局更改iOS端的条形文本颜色(我通常将它们放在Forms.Init()LoadApplication()行之间:

UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes { TextColor = UIColor.White });

Android Way: Android方式:

And then you could do it globally in your Android project by applying the correct theme. 然后,您可以通过应用正确的主题在Android项目中全局进行此操作。 See this link for an example or that (look for the Style action bar tab text and color color selector part). 请参阅此链接以获取示例或该示例(查找“ 样式”操作栏选项卡文本和颜色选择器部分)。

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

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