Android Toolkit: Calligraphy for custom fonts

Android would be boring if all apps only used the Roboto typeface. But when a designer asks you to add another font, you start thinking about subclassing a lot of Views.

Calligraphy takes care of that for you. You just need to:

  1. Add the library to your build file
  2. Place your font file(s) in the assets/fronts folder
  3. Use fontPath:
<TextView fontPath="fonts/MyFont.ttf"/>

Want to set a default font and forget about it? Add this to your Application class:

@Override
public void onCreate() {
    super.onCreate();
    CalligraphyConfig.initDefault(
        new CalligraphyConfig.Builder()
            .setDefaultFontPath("fonts/MyFont.ttf")
            .setFontAttrId(R.attr.fontPath)
            .build()
    );
    //....
}

You can still use fontPath to override the default.

More information on the Calligraphy GitHub page.