简体   繁体   中英

Xamarin FontAwesome icons seen as squares with an x inside

After watching James Montemagno video guide on fonts in Xamarin , I'm having an issue with displaying the icons either in the tab view or in a button. The Intellisense works and it recognizes all the fonts within the FontAwesomeIcons.cs file downloaded from Mathew's github but displays them as an X withing a square X . Couldn't find any working solution to this. Everything is up to date.

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 in a page with the namespace working:

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

The X is seen in the android emulator, on my phone it is just a blank square if it matters.

If anything else is needed I'll add it. Thanks for all the help in advance

I think what missing is that you should include the files extension in the 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")]

More details How to use Font Awesome icons in project as an icon of ImageButton

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM