Using a .ttf or .otf font in Android is fairly straightforward. Firstly create ‘assets/fonts/’ and put the files in there. Now using Typeface.createFromAsset we can create the typeface.

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/CustomFont.ttf");

To set TextView to use this typeface we use the setTypeface function.

TextView tv = (TextView) findViewById(R.id.texty);
tv.setTypeface(tf);

You can, of course, use this in your custom views with Paint.setTypeface.

Words of Warning

In general I wouldn’t recommend using fonts other than Droid font family apart from in games. That is because Ascender Corp specifically developed the Droid font family for optimal quality and readability on small screen devices. In an application the font is typically a form in which to present some information rather than containing information itself. For example in a racing you might use a font that is elongated with spoilers resembling a car but you probably would not use such a font for an article about cars.

Limitations

As far as I’m aware it is not possible to reference a font in XML. Making something like this impossible:

<TextView
android:id = ”@+id/texty”
android:typeface = "@font/CustomFont"
/>

I think that the Android team may have purposefully excluded a mechanism for referencing custom typefaces in XML to deter people from using an insane custom font that is difficult to read and potentially quite large.

3 Responses to “Using Custom Fonts in Android”

  1. Sachin Shelke Says:

    how to set custom font to customized list in android?
    please replay….
    on sachin.worldnet@gmail.com

    [Reply]

    hejp Reply:

    I guess you’d have to set the typeface with setTypeface in the getView function of the Adapter that your list is using.

    [Reply]

    chanakya Reply:

    but its not working in the case of list can u show me some example that would be help full for me..
    thanks & regards
    chanakya V

    [Reply]

Leave a Reply