我需要为我的应用中的不同标签指定不同的FontFamily。我需要使用默认字体(例如Roboto for Android和Helvetica for iOS)及其修改(例如Light,Medium,Bold)。据我了解,我应该使用Roboto-Light和Helvetica-Light来获得Light版本的字体(对于Medium和Bold来说也是一样)。 除了这个要求,我需要设置字体在XAML(如described in documentation),所以我结束了这段代码XAMARIN:跨平台FontFamily
<StackLayout BackgroundColor="#F8F8F8" Padding="0, 20, 0, 0">
<Label Text="Black" TextColor="#000000" >
<Label.FontSize>
<OnPlatform x:TypeArguments="x:Double"
iOS="17"
Android="16"
WinPhone="16" />
</Label.FontSize>
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>Helvetica-Black</OnPlatform.iOS>
<OnPlatform.Android>Roboto-Black</OnPlatform.Android>
<OnPlatform.WinPhone></OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
<Label Text="Light" TextColor="#000000">
<Label.FontSize>
<OnPlatform x:TypeArguments="x:Double"
iOS="17"
Android="16"
WinPhone="16" />
</Label.FontSize>
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>Helvetica-Light</OnPlatform.iOS>
<OnPlatform.Android>Roboto-Light</OnPlatform.Android>
<OnPlatform.WinPhone></OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
<Label Text="Medium" TextColor="#000000" >
<Label.FontSize>
<OnPlatform x:TypeArguments="x:Double"
iOS="17"
Android="16"
WinPhone="16" />
</Label.FontSize>
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>Helvetica-Medium</OnPlatform.iOS>
<OnPlatform.Android>Roboto-Medium</OnPlatform.Android>
<OnPlatform.WinPhone></OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
<Label Text="Bold" TextColor="#000000">
<Label.FontSize>
<OnPlatform x:TypeArguments="x:Double"
iOS="17"
Android="16"
WinPhone="16" />
</Label.FontSize>
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>Helvetica-Bold</OnPlatform.iOS>
<OnPlatform.Android>Roboto-Bold</OnPlatform.Android>
<OnPlatform.WinPhone></OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
然而,结果Android是意想不到的。不同标签的FontFamily不会更改。他们都看起来一样。
iOS中相同的代码工作预期
我的问题是:如何获得的Roboto光强,的Roboto介质和的Roboto粗体字体在我的Android应用程序中,如果下面的XAMARIN文档不起作用?
感谢您注意到sans-serif字体家族实际上使用了自Android 4.1以来的Roboto字体。 我只有一个除了你的答案。请注意,不像helvetika-bold,没有sans-serif-bold(或类似的)字体。为了将字体设置为粗体,我将Label.FontAttributes属性设置为粗体。这实现了我的要求。或者至少在设计师看看应用程序之前实现它们:) –
第一个答案[here](http://stackoverflow.com/questions/12128331/how-to-change-fontfamily-of-textview-in- android)也证实了这一说法。 –
@SushiHangover - 您上面张贴的链接现在表示自定义字体现在可在Android上使用。不过,尽管遵循了文章中的步骤,但我并未在Android上看到我的自定义字体。你知道自定义字体实际上是否仍然不支持Android? –