Sunday, January 8, 2012

Android: How to use True Type Fonts (TTF) in your View

The stock fonts provided with Android aren't bad, but if you need to give your app/game a bit more mood then you need some custom fonts.

To embed a custom font into your app, you need to create an "assets/fonts" folder and copy your TTF file there.

In your code:

Typeface font = Typeface.createFromAsset(this.getContext().getAssets(), "fonts/Jokerman.ttf");
TextView tv = (TextView) v.findViewById(res);
tv.setTypeface(font);

zl3c8
Can't get much easier than that!

Source

No comments:

Post a Comment

Leave your thoughts ...

---
If you are having trouble with copy/pasting in comments, you need to sign in or click 'Preview'.

For more information about this Firefox bug, see here.