xamarin - Font Awesome 仅在 xamarin 上显示 ASCII 字符
问题描述
TL;博士
Font Awesome 5 Solid 仅在我的 xamarin 应用程序中显示 ASCII 字符,但不显示特殊字体真棒字符。
我的情况:
我已将Font Awesome 5 Solid字体添加到我的 xamarin 项目中以使用大麻图标
这些是我添加字体的步骤:
将 .otf 文件添加到 Android
Assets
文件夹在我的 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>
问题:
A-Z 0-9
当我使用 HTML 实体代码和特殊 ASCII 字符(Å
甚至可以正常工作)访问它们时,正常的 ASCII 字母可以正常工作。如果我使用Text="I"
,这会导致标签将字母1
作为其文本,正如预期的那样。
Font Awesome 5 Solid 的大麻符号是f55f
,但是当我将其包含Text="#xf55f;"
在标签中时,我得到了带有十字的小盒子(字符未找到错误)。
解决方案
像这样更改 App.xaml 怎么样:
<OnPlatform x:TypeArguments="x:String"
x:Key="FontAwesomeSolid">
<On Platform="Android"
Value="FontAwesome5Solid.otf#Regular" />
<On Platform="iOS"
Value="FontAwesome5Free-Solid" />
<On Platform="UWP"
Value="/Assets/FontAwesome5Solid.otf#Font Awesome 5 Free" />
</OnPlatform>
参考:https ://medium.com/@tsjdevapps/use-fontawesome-in-a-xamarin-forms-app-2edf25311db4
推荐阅读
- java - 我想在谷歌地图中显示交通并用同一个按钮隐藏它
- java - 获取从查询返回的对象值
- haskell - Haskell:找不到模块“Data.List.Split”
- javascript - 从 JavaScript 中更改 OnMouseOut 事件只能暂时有效
- reactjs - 将使用 create-react-library 创建的单个反应组件嵌入到 html 页面中
- dialog - 中间的材质对话框
- php - 将最大数据大小从 php 增加到 shell_exec
- python - 类实例中的随机值,未保存
- python - Python:为什么每个项目都重复这个循环?
- ios - UITable 视图控制器上的渐变背景