Here’s how to use custom fonts in your Android application.
- Select your font – for example, Ubuntu. Make sure you use a royalty-free font (such as that one) or you pay the appropriate licensing fee (because you could get in a world of legal pain and because don’t be a dick)
- In the root folder of your Android project, make sure there’s a folder called
assets/fonts
. Thefonts
subdirectory is entirely optional but to my taste. - You cannot specify the font (really the typeface) in your resources, so you have to do in code as follows
Typeface font = Typeface.createFromAsset(_activity.getAssets(), "fonts/Ubuntu-Bold.ttf"); textView.setTypeface(font);And that’s it.
No comments:
Post a Comment