开发者

Custom Font Issue In Android

开发者 https://www.devze.com 2023-01-16 00:00 出处:网络
I am trying to use开发者_StackOverflow中文版 custom font in android. I have written java code as given below.

I am trying to use开发者_StackOverflow中文版 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


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

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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消