An Android device comes with 3 basic fonts – Droid Sans, Droid Sans Mono, and Droid Serif. These are sufficient for every day use, but for your custom apps you will most probably want to use your own font. This post will show you how you can do so.
First Steps
First step is to pick a font that you want to use. For this example, we’ll be using BPReplay, an OpenType font that I stumbled across here.
Hot looking font! 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 directory and copy our font there.
That’s it for the setup, now on to the code.
The Code
To access our custom font, we use the Typeface class in the Android SDK to create a typeface that Android can use, then set any display elements that need to use our custom font appropriately. To demonstrate, we’ll create two text views on our main screen, one using the default Android Sans font, and the other using our BPReplay font. The layout is below.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns: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>
</LinearLayout>
The code to load and set the custom font is straight forward as well, and is shown below.
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/BPreplay.otf");
TextView tv = (TextView) findViewById(R.id.CustomFontText);
tv.setTypeface(tf);
}
}
You can see on line 8 where we instantiate a new Typeface object from our font definition file. On lines 9 and 10, we set the text view to use our custom font. The result us shown below.
Sure enough, we have a different font on the screen. Using another freeware font called Molot, our font goodness becomes even more apparent.

[...] itself as being about “Coding and managing in the .NET space”, recently ran the excellent Android Development – Using Custom Fonts. You’ve always been able to use your own fonts in your own apps, but the how-to coverage has been [...]
[...] itself as being about “Coding and managing in the .NET space”, recently ran the excellent Android Development – Using Custom Fonts. You’ve always been able to use your own fonts in your own apps, but the how-to coverage has been [...]
[...] itself as being about “Coding and managing in the .NET space”, recently ran the excellent Android Development – Using Custom Fonts. You’ve always been able to use your own fonts in your own apps, but the how-to coverage has been [...]
[...] itself as being about “Coding and managing in the .NET space”, recently ran the excellent Android Development – Using Custom Fonts. You’ve always been able to use your own fonts in your own apps, but the how-to coverage has been [...]
[...] itself as being about “Coding and managing in the .NET space”, recently ran the excellent Android Development – Using Custom Fonts. You’ve always been able to use your own fonts in your own apps, but the how-to coverage has been [...]
[...] itself as being about “Coding and managing in the .NET space”, recently ran the excellent Android Development – Using Custom Fonts. You’ve always been able to use your own fonts in your own apps, but the how-to coverage has been [...]
[...] itself as being about “Coding and managing in the .NET space”, recently ran the excellent Android Development – Using Custom Fonts. You’ve always been able to use your own fonts in your own apps, but the how-to coverage has been [...]
[...] itself as being about “Coding and managing in the .NET space”, recently ran the excellent Android Development – Using Custom Fonts. You’ve always been able to use your own fonts in your own apps, but the how-to coverage has been [...]
[...] itself as being about “Coding and managing in the .NET space”, recently ran the excellent Android Development – Using Custom Fonts. You’ve always been able to use your own fonts in your own apps, but the how-to coverage has been [...]
Ooh, thanks. Apparently .otf files work. I used a .ttf file and it worked, too.
Good info, thanks!
There is no other sub folder like fonts where i can add new fonts in assets? Can any one help for me in this regard
thank in advance
You can create that yourself in Eclipse. Just right-click the “assets” folder and click New->Folder. The folder will then be created in your project and should be ready for use.
[...] itself as being about “Coding and managing in the .NET space”, recently ran the excellent Android Development – Using Custom Fonts. You’ve always been able to use your own fonts in your own apps, but the how-to coverage has been [...]
I have a question and it would be great if you could help me out.
I have an Android phone, and I would like to add “Persian/Farsi” font so I can browse websites that are composed in Farsi.
could you please let me know how it can be done?
I must admit that i am very illiterate about Android.
cheers,
A.J.
Thanks! I know this post is almost a year old but it helped me today. This worked perfectly for me using a .tff file. Thanks again!
u are so good at Android software system, I would like to ask you about Unicode I try to past the unicode according to your instruction as above but it still display incorrectly
you can check here
I hope you will give any solution to view correctly of my unicode language
Thank you
dara sun
Cambodia
http://i51.tinypic.com/243npu0.png
Where can I find those fonts?
I need Tahoma and Dingbats.
Thx in advance for help!
lessa
.. already found (windows/fonts) – silly question, sorry!
thanks, it helped me today
For some reason this works only for API levels 3 to 7
It dosn’t work for API level 8 and above.
Thank you!!!
does android support urdu fonts? if yes then kindly tell me the name of that urdu font?
Thannkkkk uuuuuuuuuuu
Cheeeetaaaaaaaa
thanks for your quick and efficient tutorial
[...] The rest of my Player code relies on more callbacks for MediaPlayer (like OnSeekCompleteListener and OnCompletionListener), a headless speech recognizer implementation (a bunch more callbacks), a really clean swipe gesture implementation for "flipping the page" without having to go through the speech-recognition rigamarole (you guessed it, more callbacks). And a button that toggles/indicates listening/matching state and uses some icons from the free version of GLYPHICONS (note, Glyphish is another stylish option I've used for other projects). Handler.postDelayed(someCoolRunnable, milliseconds) takes care of pausing the video when an animation "page" is complete. The PlayerActivity is also wrapped up in a FrameLayout with a custom font, to boot (code tips for custom fonts). [...]
i hope android suport font khmer soon….
if how to inlude font this OS , please tell me ucz i want my people
easy use this OS. thank u advance
u_eang@yahoo.com
I’m Getting Error…. Don’t What’s the Problem is…
[...] http://www.barebonescoder.com/2010/05/android-development-using-custom-fonts/ [...]
how can i install local languages fonts in my tablet.
ur help will be appreciated
thank you in advance
i got exception Caused by: java.lang.RuntimeException: native typeface cannot be made
How to resize custom font ?
ya its work nice thx
[...] discussion by itself, let’s skip that and investigate if we can support fonts. There are few blogs explaining how one can add new fonts. The general idea here is to add the font to assets in project [...]
[...] You may refer to these links as well:http://developer.android.com/guide/topics/ui/themes.htmlhttp://www.androidengineer.com/2010/06/using-themes-in-android-applications.htmlIf you want to use custom font then have a look at this :http://www.barebonescoder.com/2010/05/android-development-using-custom-fonts/ [...]
I have tried this method with a ghanaian( West African Country) font and the font is still appearing as rectancles on the android phone. PLease help!!
If you want to display custom font or Indian Language like Malayalam please see this site. It explained in a simple way.
http://android-helper4u.blogspot.com/2013/02/10-how-to-display-local-language-text.html
[...] “Man, screw typography on Android!” but calm your nerd rage son, for you can indeed imbed custom fonts into your app! There is a caveat that you custom fonts can’t be used one a homescreen widget. You have to [...]