0

I am trying to use a custom font in my app but I am getting an error. My code is this:

Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/Oxigen_Regular.ttf");
     TextView texto_titulo =(TextView) findViewById(R.id.ref_articulo);
     texto_titulo.setTypeface(myTypeface);

I have the font in fonts folder inside assets folder. I don´t know what is happening, I am doing this in ActionBarActivity. It says: "native typeface cannot be made". Someone knows the solution? Thanks in advance.

user3383415
  • 437
  • 1
  • 7
  • 22

4 Answers4

1

your code is this:

"fonts/Oxigen_Regular.ttf"

which means, you "must" have your font file under fonts folder, with case sensitive letters, including the ttf extenstion.

if original font name is: Oxigen_Regular.TTF or oxigen_regular.ttf inside your fonts asset folder, your code Oxigen_Regular.ttf will give error. It needs to be precisely the same as that you write programmatically.

canova
  • 3,965
  • 2
  • 22
  • 39
0

if you want to use any external font means you have to download and put it in assets folder in application. use this link for download fonts

http://www.1001freefonts.com/

use this code

TextView txt = (TextView) findViewById(R.id.custom_font);  
Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf");  
txt.setTypeface(font); 
Sreekanth
  • 407
  • 4
  • 8
  • 20
0

You can oxigen.ttf keep in assets/oxigen.ttf (should be small latter oxigen.ttf)

and then call

TextView texto_titulo =(TextView) findViewById(R.id.ref_articulo);
Typeface tf = Typeface.createFromAsset(getAssets(), "oxigen.ttf");
        texto_titulo.setTypeface(tf, Typeface.BOLD);

must be import

import android.graphics.Typeface;

I am sure you solve 100%. Best of luck!

0

The issue was that the font that I downloaded was corrupt... I have downloaded from a new repository and now works perfectly. Sorry.

user3383415
  • 437
  • 1
  • 7
  • 22