Use external fonts in android Use external fonts in android android android

Use external fonts in android


AFAIK, Android does not support OpenType. Use a TrueType font instead.


UPDATE: Apparently OpenType is now supported, at least somewhat. It was not supported originally, so you will want to test your font thoroughly on whatever versions of Android your app will support.


In order to access our font easily, we need to bundle it with our application in a way that our code can subsequently load it. To do this, we create a Fonts folder in our assets direct

This may be your .xml

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextView    android:id="@+id/DefaultFontText"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:textSize="30sp"    android:text="Here is some text." /><TextView    android:id="@+id/CustomFontText"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:textSize="30sp"    android:text="Here is some text.">    </TextView>

Write following code in your .java class

Typeface tf = Typeface.createFromAsset(getAssets(),            "fonts/BPreplay.otf");    TextView tv = (TextView) findViewById(R.id.CustomFontText);    tv.setTypeface(tf);


Android does support OTF (I'm not sure from which SDK version but it definitely works with 1.6), I was using a typewriter OTF font for a while but the rendering is nowhere near as accurate as with the TTF version I ended up using (via online font converter). The baseline was all over the place (some letters were a full 2 pixels higher than others), and on LDPI phones like the HTC Wildfire the problem is greatly magnified due to the larger pixels.