1

As the title suggest, the font file seems that can't be found. I quote the error:

Unhandled Exception:

Java.Lang.RuntimeException: Font asset not found fontawesome-webfont.ttf"

The code is:

public class MainActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.Main);

        AssetManager assets = this.Assets;
        Typeface font = Typeface.CreateFromAsset(assets, "fontawesome-webfont.ttf");

        // Set our view from the "main" layout resource
        Button button = (Button)FindViewById(Resource.Id.btnIniciarSesion);
        button.SetTypeface(font, TypefaceStyle.Normal);

        // Get our button from the layout resource,
        // and attach an event to it
    }
}

The font file is in the assets folder, as you can see in the following image:

font file inside assets folder

What can I try?

Pablo De Luca
  • 795
  • 3
  • 15
  • 29
  • 1
    Is the font Build Action set to AndroidAsset? Another problem could be that the way you are typing the font might not actually be the name of the contained font. For example, I use the Segoe font in my Xamarin apps and the UISegoe named font lives in the UISegoeRegular.ttf. You can figure this out by opening the font in a font viewer like http://us.fontviewer.de/ – BrewMate Nov 10 '16 at 23:38
  • @BrewMate i tried with your suggestion and didn't work. The font Build Action was in AndroidAsset by default. So I tried with the name of the font like in a font viewer is shown ("FontAwesome") and the issue persist. – Pablo De Luca Nov 11 '16 at 13:25
  • 1
    I do this in my code and it works for me: `Typeface font = Typeface.CreateFromAsset ("SegoeUI", "SegoeUIRegular.ttf");` – BrewMate Nov 11 '16 at 15:10

4 Answers4

1

Try this,

Typeface font = Typeface.createFromAsset(getContext().getAssets(),  "fontawesome-webfont.ttf");
Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77
1

you should set in "fontawesome-webfont.ttf" file properties -> build Action and choose AndroidAsset

Evgeniy
  • 75
  • 1
  • 9
0

I deleted and created again the solution and the problem has 'magically' disappeared.

Pablo De Luca
  • 795
  • 3
  • 15
  • 29
0

try this instruction it work for me

Typeface oswaldFont = Typeface.CreateFromAsset(Assets, "Oswald.ttf");
Younes
  • 46
  • 2