【问题标题】:Xamarin FontAwesome icons seen as squares with an x insideXamarin FontAwesome 图标被视为带有 x 的正方形
【发布时间】:2021-07-18 06:55:10
【问题描述】:

观看James Montemagno video guide on fonts in Xamarin 后,我在标签视图或按钮中显示图标时遇到问题。 Intellisense 可以工作,它可以识别从Mathew's github 下载的 FontAwesomeIcons.cs 文件中的所有字体,但会将它们显示为带有正方形 的 X。找不到任何可行的解决方案。一切都是最新的。

assemblyinfo.cs:

using Xamarin.Forms.Xaml;

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
[assembly: ExportFont("Font Awesome 5 Brands-Regular-400", Alias = "FAB")]
[assembly: ExportFont("Font Awesome 5 Free-Regular-400", Alias = "FAR")]
[assembly: ExportFont("Font Awesome 5 Free-Solid-900", Alias = "FAS")]

AppShell:

<Shell.Resources>
   <ResourceDictionary>
      <Style TargetType="ShellContent" x:Key="PricingPage">
                <Setter Property="Icon">
                    <Setter.Value>
                        <FontImageSource FontFamily="FAS" Glyph="{x:Static fontAwesome:FontAwesomeIcons.BalanceScale}"/>
                    </Setter.Value>
                </Setter>
       </Style>
   </ResourceDictionary>
</Shell.Resources>
<TabBar>
        <Tab Title="PricingPage" Style="{StaticResource PricingPage}" >
            <ShellContent Title="PricingPage"   Route="PricingPage" ContentTemplate="{DataTemplate local:ProductPricing}" />
            <ShellContent Title="ExistingProductPricing" IsVisible="False" Route="ExistingProductPricing" Shell.FlyoutBehavior="Disabled" ContentTemplate="{DataTemplate local:ExistingProductPricing}" /> 
        </Tab>
 </TabBar>

页面中命名空间正常工作的按钮:

<Button
    Text="{x:Static fontAwesome:FontAwesomeIcons.CheckCircle}"
    FontFamily="FAS"/>

X 出现在 android 模拟器中,在我的手机上,如果重要的话,它只是一个空白方块。

如果还需要什么我会补充的。提前感谢所有帮助

【问题讨论】:

    标签: c# xamarin xamarin.forms font-awesome-5


    【解决方案1】:

    我认为缺少的是您应该在 ExportFont: 中包含文件扩展名:

    using Xamarin.Forms.Xaml;
    
    [assembly: XamlCompilation(XamlCompilationOptions.Compile)]
    [assembly: ExportFont("Font Awesome 5 Brands-Regular-400.ttf", Alias = "FAB")]
    [assembly: ExportFont("Font Awesome 5 Free-Regular-400.ttf", Alias = "FAR")]
    [assembly: ExportFont("Font Awesome 5 Free-Solid-900.tff", Alias = "FAS")]
    

    更多详情How to use Font Awesome icons in project as an icon of ImageButton

    【讨论】:

    • 非常感谢!我添加了我的 otf 扩展,它就像一个魅力。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    • 2018-06-27
    • 1970-01-01
    相关资源
    最近更新 更多