How to change font for entire Android application?

This can be easy but if you don’t know how to do it, it gets you! In this post I will show how to change font for whole Android application. For this purpose will will use ready-to-use library. You can see this library project in github.

1. First of all download library file: calligraphy-1.1.0
2. Add library to your project: add jar file into libs folder. Right click on jar file on Eclipse and add to build path.
3. Create fonts folder in your assets folder. Then copy your font file into it.
4. In your activity, inside onCreate() method, add this line

CalligraphyConfig.initDefault("fonts/GothaProReg.otf", R.attr.fontPath);

5. Add this code snippet outside of onCreate() method:

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(new CalligraphyContextWrapper(newBase));
    }

6. Create new xml file in res/values folder: fontPath.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="fontPath" format="string"/>
</resources>

Run the project in order to check that out!

UPDATE

This post was written while ago. Author of Calligraphy library is working on this library project seriously and library is getting updates. Now, this is time to move on to 2.0.2 version. Okey let’s start!

1. First of all, in your paste this in order to download library:

dependencies {
    compile 'uk.co.chrisjenx:calligraphy:2.0.2'
}

2. Now create ‘fonts’ folder in your ‘assets’ folder and paste your TTF or OTF file inside ‘fonts’ folder.
3. In your activity’s onCreate method write this:

CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                        .setDefaultFontPath("fonts/gothic720-lt-bt-light.ttf")
                        .setFontAttrId(R.attr.fontPath)
                        .build());

4. Inside your activity(but outside of onCreate)

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
    }

5. Create ‘fontPath.xml’ file inside res/values folder:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="fontPath" format="string"/>
</resources>

Now you can check your application! You can see that your entire application font has been changed! =)