使用Xamarin Forms(2.3.1)和Prism(6.2)开发适用于iOS和Android的应用程序我们很难让自定义字体在Android上运行,但iOS已经很好了 .
我们已经关注the most recent documentation(即不使用自定义渲染),似乎已将其缩小为与Prism相关...
为了简化问题我们制作了一个新的Forms App,将Xamarin demo中的Lobster-Regular.ttf添加到Android Assets和iOS Resources并确保其属性分别为AndroidAsset和BundleResource,然后在默认的xaml页面中添加:
<Label Text="Hello Forms with XAML">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>MarkerFelt-Thin</OnPlatform.iOS>
<OnPlatform.Android>Lobster-Regular.ttf#Lobster-Regular</OnPlatform.Android>
<OnPlatform.WinPhone></OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
(这也是演示中的直接)
它适用于iOS和Android .
如果我们创建一个新的Prism Unity应用程序,添加字体文件,检查属性(默认正确)并在MainPage.xaml中插入标签iOS将使用自定义字体,但Android将只使用标准字体 .
有一个known issue with custom fonts in UWP and WP apps但这似乎没有关系 .
所有测试都在iOS模拟器和Android模拟器上进行 .
Update 根据Dan S. 's comment I' ve上传了一个项目,以显示一个最小的棱镜应用程序,其自定义字体适用于iOS而不是Android:sample project
1 回答
根据您提供的解决方案,问题似乎与您在项目中使用的Xamarin Forms版本有关 . 您的样本使用X.F 2.3.1.114,Xamarin的样本使用2.3.3.180 . 更新至少2.3.3.180可以解决样本中的问题 . 更新到Prism 6.3.0-pre2也有效(但只是因为它将Xamarin Forms更新到最新版本) .