问题描述
TL; DR
Font Awesome 5 Solid仅在我的xamarin应用程序中显示ASCII字符,但不显示特殊字体真棒字符。
我的处境:
我已经在我的xamarin项目中添加了Font Awesome 5 Solid字体以使用the cannabis icon
这些是我添加字体的步骤:
-
在App.xaml中为每个平台定义字体名称,如下所示:
<OnPlatform x:TypeArguments="x:String" x:Key="FontAwesomeSolid"> <On Platform="Android" Value="FontAwesome5Solid.otf" /> <On Platform="iOS" Value="FontAwesome5Free-Solid" /> <On Platform="UWP" Value="/Assets/FontAwesome5Solid.otf" /> </OnPlatform>
然后,我尝试像这样访问xaml
<span>
中的字体:
<Span Text=""FontFamily="{StaticResource FontAwesomeSolid}" />
作为参考,请参见下面的整个代码块。
<Label.FormattedText>
<FormattedString>
<Span Text=""FontFamily="{StaticResource FontAwesomeSolid}" />
<Span Text="{Binding Source={x:Static model:User.rating},StringFormat='{0}'}"
Style="{StaticResource MenuLabel}">
<Span.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}" />
</Span.GestureRecognizers>
</Span>
</FormattedString>
</Label.FormattedText>
问题:
当我使用HTML实体代码访问它们时,正常的ASCII字母(如A-Z 0-9
可以正常工作,而特殊的ASCII字符(如Å
)也可以正常工作。如果我使用Text="I"
,则会导致标签上带有字母1
作为文本,这与预期的一样。
Font Awesome 5 Solid的大麻符号为f55f
,但是当我在标签中包含Text="#xf55f;"
时,我得到带有叉号的小框(找不到字符错误)。
解决方法
如何像这样更改App.xaml:
IAM & Admin > Quotas > Select project"
参考:https://medium.com/@tsjdevapps/use-fontawesome-in-a-xamarin-forms-app-2edf25311db4