如何在Xamarin Forms Android中设置页面标题字体族和大小

4
我正在使用Xamarin Forms开发Android应用程序,页面文件是用XAML创建的。但是标题字体属性更改无效。我的代码如下:
 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
         x:Class="MasterDetailPageNavigation.ContactsPage"
         Title="Home"
         BackgroundColor="#ff6600">
      <ContentPage.Content>
          <StackLayout Padding="110,190,100,80">
            <Button  BackgroundColor="Transparent" TextColor="White" Image="Button.png"/>
  <StackLayout Padding="25">
  <Label  Text="Button" TextColor="#ffffff" FontSize="Small"></Label>
  </StackLayout>
</StackLayout>
</ContentPage.Content>

如何更改标题字体样式?

你是在说ActionBar/Toolbar的标题吗? - jzeferino
请参考以下页面链接:Sheets - Aboobakkar P S
https://dev59.com/sWcs5IYBdhLWcg3wYy9T - Akash Amin
如果我的回答对您有帮助,请将其标记为正确。这是一个很好的stackoverflow惯例。我非常感激。 - jzeferino
2个回答

3

从这个答案开始,在ContentPage中添加:

<NavigationPage.TitleView>
    <Label VerticalOptions="Center" MaxLine="1" FontFamily="/*OUR FONT GOES HERE*/" Text="Our new title" />
</NavigationPage.TitleView>

或者:
<Shell.TitleView>
   <Label VerticalOptions="Center" MaxLine="1" FontFamily="/*OUR FONT GOES HERE*/" Text="Our new title" />
</Shell.TitleView>

1

请在MainActivity.csLoadApplication(new App());下面尝试一下这个。

var spannableString = new SpannableString(SupportActionBar.Title);
spannableString.SetSpan(new TypefaceSpan("yourfont.ttf"), 0, spannableString.Length(), SpanTypes.ExclusiveExclusive);
SupportActionBar.TitleFormatted = spannableString;

使用 Android.Text; 和使用 Android.Text.Style; - jzeferino
如果我的回答对您有所帮助,请将其标记为正确答案。这是一个不错的Stack Overflow实践。我非常感谢。 - jzeferino
@jzeferino,对我没有用。我使用的是.ttf文件,在共享代码上运行得很好,并更改标签、输入框、跨度等...,但是当按照指示使用该代码时,它无效。 - Ali123
@Ali123 我已将代码更改为ttf格式。但是Android支持otf格式。 - jzeferino

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接