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
Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk: ravi@androidhive.info
  • Anuj D

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

  • Lifon

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

  • george

    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 george.celsie@gmail.com . Thanks ang
    good luck for all your projects..

  • Ravi Sharma

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

  • sri

    Could you post solution for this

  • Pravin

    getAssets() method giving me error

    • divya

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

  • Divya

    Great article

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

  • sheik

    can u post for barcode scanner by using camera

  • Srujana Dakoju

    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

      how to change typeface on a ListView?

    • Nana Medo

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

  • Sneha Divakaran

    thakarthuuuuuu,adipoliii

  • THEMBO CHARLES LWANGA

    Thank u Ravi

  • vinod

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

  • vinod

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

  • Jan

    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

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

  • gurcharansinghgill6

    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

    Thanks a lot sir.

  • Marzena

    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

    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

    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