Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to use FontAwesome in the XAML in a Xamarin.Forms App?

FunPlay3rsFunPlay3rs Member ✭✭

Hey,

Does someone know how to use the FontAwesome otf File for nice Icons in Xamarin Forms?
I imported all the Files for Android and iOS und put them in the Asset/Ressource Folder.
Know I edited my ResourceDictionary and added a OnPlatform Tag for the FontAwesome Font.
<OnPlatform x:TypeArguments="x:String" x:Key="FontAwesomeBrands"> <On Platform="Android" Value="Font Awesome 5 Brands-Regular-400.otf#Font Awesome 5 Free Regular" /> <On Platform="iOS" Value="Font Awesome 5 Free" /> </OnPlatform>
The File name is "Font Awesome 5 Brands-Regular-400.otf".

But when I start my App it looks like this:

I also tried it with different Values in the "On Platform" tag. I'm currently testing the App on a Android Phone (tested on Android 8 and Android 10).

In the XAML I implemented it like this:
<Button x:Name="btn_logout" Text="&#xf2f5;" FontFamily="{DynamicResource FontAwesomeBrands}" HorizontalOptions="End" HeightRequest="70" Margin="10,10,10,10"/>

I also tried "\uf2f5" as text and also tried a StaticResource, but nothing worked :(
The Icon I use is called "sign-out-alt".

Does someone know why this doesn't work.
And yes the BuildAction is set to AndroidAsset.

Thanks for your help,
Dominic

Best Answer

Answers

  • FunPlay3rsFunPlay3rs Member ✭✭

    @ColeX said:
    You code is correct , change the file extension from otf to ttf , add into project and try again .

    Same thing works fine on my side .

    Hmm... Didn't work :(
    <OnPlatform x:TypeArguments="x:String" x:Key="FontAwesomeBrands"> <On Platform="Android" Value="Font Awesome 5 Brands-Regular-400.ttf#Font Awesome 5 Free Regular" /> <On Platform="iOS" Value="Font Awesome 5 Free" /> </OnPlatform>
    Don't know why...

  • FunPlay3rsFunPlay3rs Member ✭✭

    @FunPlay3rs said:

    @ColeX said:
    You code is correct , change the file extension from otf to ttf , add into project and try again .

    Same thing works fine on my side .

    Hmm... Didn't work :(
    <OnPlatform x:TypeArguments="x:String" x:Key="FontAwesomeBrands"> <On Platform="Android" Value="Font Awesome 5 Brands-Regular-400.ttf#Font Awesome 5 Free Regular" /> <On Platform="iOS" Value="Font Awesome 5 Free" /> </OnPlatform>
    Don't know why...

    Never mind... Worked now :D Thanks :)

Sign In or Register to comment.