Friday, 6 May 2011

Using a True-Type Font in your Android app

Android supports true-type fonts, but these have to be set in code, you cannot specify the fonts in the layout XML.

Firstly copy the font file into your assets folder. I usually create a fonts sub-folder:


Second, and finally, apply the font to a TextView in code:

TextView tv = (TextView)findViewById(;
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf");

TextViews, Buttons, CheckedTextView and RadioButtons all have the setTypeface method, but as a note of warning, not all .ttf files will necessarily display in your Android app, if it fails your app will force close with the following error: RuntimeException: native typeface cannot be made.


Post a Comment