RATTLESNAKE
RATTLESNAKE

Reputation: 3228

Custom Font Issue In Android

I am trying to use custom font in android. I have written java code as given below.

TextView txt = (TextView) findViewById(R.id.customfont);
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Molot.otf");
txt.setTypeface(font);

where I have stored the custom font in "./assets/fonts/" folder.

But, I am getting nullpointerexception on the 3rd line.

Can anybody give me the solution for this issue? Thanks

Upvotes: 11

Views: 4835

Answers (3)

tiranodev
tiranodev

Reputation: 1003

Try this
Typeface font = Typeface.createFromAsset(getAssets(), "/fonts/Molot.otf");

Upvotes: 0

Rahul Arora
Rahul Arora

Reputation: 1036

Android supports OTF as well. Your font may be corrupt.

Download delicious font from www.exljbris.com/delicious.html. It is an otf font and it works for me.

Upvotes: 1

DeRagan
DeRagan

Reputation: 22930

Android supports only TTF font type not OTF. Check this link

"RuntimeException: native typeface cannot be made" when loading font

Upvotes: 8

Related Questions