Loading external fonts in your android application is very easy. It can be achieved with only two lines of code.

Download Code

Start a new Project

1. Create a new project and fill the required details. File ⇒ New Project.
2. Create a folder called fonts under assets folder and place all your fonts in it. (Folder name can be anything)

android using external fonts

3. Open your main.xml and create a simple textview.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#222222" >

    <TextView
        android:id="@+id/ghost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textSize="70dip"
        android:gravity="center"
        android:textColor="#ef0000"
        android:layout_marginTop="50dip"
        android:text="ghost" />

</LinearLayout>

4. Now open your MainActivity class file and try following code. In the following code i am importing font from assets folder and using TypeFace class i am applying custom font on textview label.

package com.example.androidhive;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

public class AndroidExternalFontsActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Font path
        String fontPath = "fonts/Face Your Fears.ttf";

        // text view label
        TextView txtGhost = (TextView) findViewById(R.id.ghost);

        // Loading Font Face
        Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);

        // Applying font
        txtGhost.setTypeface(tf);
    }
}

5. Run your project.

android loading external fonts
This image is for thumbnail purpose.
android using external fonts
Subscribe
Notify of
guest
60 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Anuj D
Anuj D
8 years ago

Thanks.. Its really easy. 🙂 Your many articles helped me a lot…
Good work.. Keep it up 🙂

Lifon
Lifon
8 years ago

At first thanks for such a tutorial.
but, how can I use these custom fonts in my list view?

george
george
7 years ago

Hi all. I am a novice in developing app and thanks to
Ravi for all good work that is doing . I’m working at a simple app and I get
stuck . if you have knowledge of
building android apps, and make team
with me please replay to [email protected] . Thanks ang
good luck for all your projects..

Ravi Sharma
Ravi Sharma
7 years ago

hiii ravi
how can change the custom font in XML file,i dont want to make the object of TextView in my application.

sri
sri
7 years ago

Could you post solution for this

Pravin
Pravin
7 years ago

getAssets() method giving me error

divya
divya
7 years ago
Reply to  Pravin

Try getActivity().getAssets() instead of just getAssets()

Divya
Divya
7 years ago

Great article

arpan
7 years ago

Hi Ravi ! How I use .ttf font in String.xml under ” ”
please guide me

sheik
sheik
7 years ago

can u post for barcode scanner by using camera

Srujana Dakoju
Srujana Dakoju
6 years ago

hi all, I have an activity in which there is a button. On clicking that button a custom dialog box will appear(I wrote a separate java and XML file for the custom dialog box). I can change the font in the activity but unable to change the font in the dialog. Here is my code for Custom Dialog box. Its showing an error at getAssests() method. Can anyone tell me how to change the font in the dialog box.

package com.log.srujlogin;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class CustomDialogClass extends Dialog implements
android.view.View.OnClickListener {

public Activity c;
public Dialog d;

public CustomDialogClass(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_custom_dialog_class);

TextView done = (TextView)findViewById(R.id.done);
Typeface custom_font = Typeface.createFromAsset(getAssets(),
“fonts/AvenirNextLTPro-Regular.otf”);
done.setTypeface(custom_font);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.resend_link:
break;
default:
break;
}
dismiss();
}

}

João Paulo Mendes de Carvalho
João Paulo Mendes de Carvalho
6 years ago
Reply to  Srujana Dakoju

how to change typeface on a ListView?

Nana Medo
Nana Medo
6 years ago
Reply to  Srujana Dakoju

use (this.getAsset()) instead of getAsset().

Sri Harsha Chilakapati
Reply to  Nana Medo

What makes them different? this is implicitly assumed in this case.

Sneha Divakaran
Sneha Divakaran
6 years ago

thakarthuuuuuu,adipoliii

Jobin Jeeji
Jobin Jeeji
3 years ago

Ha ha post muthalali malayali alla 🙂

THEMBO CHARLES LWANGA
THEMBO CHARLES LWANGA
6 years ago

Thank u Ravi

vinod
vinod
5 years ago

If in case fonts apply to list item in slide out menu (navigation drawer).????

vinod
vinod
5 years ago

can we apply the fonts to the array of the strings in the gridview!!!!!!!!!!!!!!!!

Jan
Jan
5 years ago

I have multiple fonts (ttf) file. and I want to show all font in a drop-down to select and change change text font. How I will get all font at once

Muhammad Naveed
Muhammad Naveed
5 years ago

Simple words, but works like a rocket, Hats off boss

gurcharansinghgill6
gurcharansinghgill6
5 years ago

Hello Sir Thanks for providing such information tutorial it saved lot of time

well code is working perfect when i am attaching English font
It also working for hindi font

But it is not working for punjabi font

I am trying to use
GurbaniAkhar font and Anmollipi

Can be downloaded here

https://www.sikhnet.com/Gurmukhi-Fonts

vandana
vandana
5 years ago

Thanks a lot sir.

Marzena
Marzena
5 years ago

Hello everyone! I would like to add new font for my TextView. After pasting Courgette Regular to my assets folder I got message on the screen: The file was loaded in the wrong encoding:’UTF-8′. Is it possible to fix this?

Yesenia Rodriguez
Yesenia Rodriguez
4 years ago

Hi, thanks for the tutorial, i just have a question.. if i want to apply the custom font to all textviews … what do i do? or i need to add an ID one by one of my textViews?

Bilal Saeed
Bilal Saeed
4 years ago

public class MyEditText extends EditText {

public MyEditText(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

init();

}

public MyEditText(Context context, AttributeSet attrs) {

super(context, attrs);

init();

}

public MyEditText(Context context) {

super(context);

init();

}

private void init() {

if (!isInEditMode()) {

Typeface tf = Typeface.createFromAsset(getContext().getAssets(), “fonts/MavenPro-Regular.ttf”);

setTypeface(tf);

}

}

}

————————-

And in Here is the code how to use it.

MyEditText editText = (MyEditText) findViewById(R.id.editText);

editText.setText(“Hello”);
————————————-
Or in Your xml File

Mitesh Makwana
Mitesh Makwana
3 years ago

hii ravi,
is it possible to apply typekit font in android?

Ravi Tamada
3 years ago
Reply to  Mitesh Makwana
Jobin Jeeji
Jobin Jeeji
3 years ago

How to apply custom font to all the textviews android

haz
haz
9 years ago

wow…..great

mlselegant
mlselegant
9 years ago

nice android hive animated logo

Marisa Oliva
Marisa Oliva
9 years ago

Very interesting

A question. There any way to import the font directly in the xml files without two lines in .java?

thanks

Marisa Oliva
Marisa Oliva
9 years ago
Reply to  Ravi Tamada

oh, thanks, I see this article before but I need to insert in style.xml. For example:

#ffffff
left
3dp
66dp
normal
“TrueType/MovistarText-Bold.ttf”>

Eliysha243
Eliysha243
9 years ago
Reply to  Ravi Tamada

Hi Ravi, how you can I contact you in private ?
thanks,

shajahan
shajahan
9 years ago

great yar. androidhive is very useful in all aspect

Mramu1989
Mramu1989
9 years ago

this site is very useful for android developers

Carvi 008
Carvi 008
9 years ago

this is very useful for us thankyou………

Autul
Autul
9 years ago

best site for learning android developement… 🙂

Ravi Tamada
9 years ago
Reply to  Autul

Thank You

Touati_wassim
Touati_wassim
9 years ago

hi haw can i add this font to webview text??

Rumman Ashraf
Rumman Ashraf
9 years ago

will all fonts be compatible ?

Ravi Tamada
9 years ago
Reply to  Rumman Ashraf

TTF fonts are supported. Recently started supporting OTF fonts too.

Rumman Ashraf
Rumman Ashraf
9 years ago
Reply to  Ravi Tamada

thanks for your tutorial really helpful 😀

PushkarJoshi
PushkarJoshi
9 years ago

//Code
tf4 = Typeface.createFromAsset( getAssets(), “CN_1.TTC”);
cn1b.setTypeface(tf4);

Tried with Japanese & chinese fonts not working any solution ?
It always remains blank .. Tried many ttf & ttc fonts ..

// SOLUTION
CH & JP Fonts are not working with API 7,8 (REMAINS BLANK) Working perfect with API 10

Nisaduwa
Nisaduwa
9 years ago

Grt example. Thankx. and can u help me how to change spinner font face.

Akhil Soni
Akhil Soni
9 years ago

thanks Ravi for Providing such a Good example 🙂

Robert Gichohi
Robert Gichohi
9 years ago

thanx alot

Meena
Meena
9 years ago

How to create “timesnewroman.ttf” file in Assets -> Fonts folder

Meena
Meena
9 years ago

Without using XML file, dynamically i have created FontType . My doubt is, how should i create “ttf” file under Assets. Could anyone help me please ?

Hariprasad Mhk
Hariprasad Mhk
9 years ago
Reply to  Meena

first download that font style file from the web. and copy it and paste it under assets folder by right clicking on the assets folder. you can get all types of fonts files on the web

Hariprasad Mhk
Hariprasad Mhk
9 years ago

hi ravi,

can we have to use the external fonts in our xml files. Please help me for this. because i am suffering for this problem since from the last 2 days. All the remaining work has been stoped about this

Ravi Tamada
9 years ago
Reply to  Hariprasad Mhk

What do you mean by using in xml file ?

Hariprasad Mhk
Hariprasad Mhk
9 years ago
Reply to  Ravi Tamada

I mean that can we have to use the external font in the propertyas android:typeface=”monospace”
at any point……

rahul
rahul
8 years ago

thnx man its very usefull…

Kunal
Kunal
8 years ago

Hi Ravi, I dont know if you would get the time to reply or not…..I want to apply ccustom fonts in a pdf file using iText…I am at my wits end. Have been trying for 72 hours…:( …followed this http://itextpdf.com/examples/iia.php?id=212

Sreenu Merugu
Sreenu Merugu
8 years ago

Hi Ravi…Could u please tell me how to use condensed bold font for android 2.2 version ?please try to send me to [email protected]

Boy
Boy
8 years ago

Thanks for example 🙂

rishabhsri20
rishabhsri20
8 years ago

what if i wanna add a font to my whole app?

60
0
Would love your thoughts, please comment.x
()
x