Typeface helper for Android
Latest commit f9e1265 Jun 6, 2016 @jskierbi jskierbi Merge pull request #5 from marcinbak/patch-1
Added method to set style to a string


Android Typeface Helper

Android lacks proper support for custom typefaces. Most obvious method of defining typeface for UI elements via XML attributes is missing from default framework views. This library makes it a lot easier to set custom typefaces from java code - one time initialization inside Application subclas and then applying custom typeface to all View's via typeface() static method call.

alt text

Sample app (sources available in sample folder):

Get it on Google Play


  • Apply custom typefaces to whole view hierarchy via single call.
  • Super easy initialization in Application subclass via TypefaceHelper.init()
  • TypefaceHelper.typeface() applies custom typeface to all TextView's inside Activity or ViewGroup
  • TypefaceHelper can also apply custom typeface to View, or create SpannableString with custom font from Strning/CharSequence
  • Support for multiple typefaces: TypefaceHelper can use default TypefaceCollection passed via init() or can be parametrized with other TypefaceCollection
  • Support for textStyles: Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC and Typeface.BOLD_ITALIC
  • Support for dynamic typeface changes
  • Support for custom typefaces in ActionBar title


Via gradle:

compile 'com.norbsoft.typefacehelper:library:0.9.0'

Alternative download AAR here


  • Put your custom true type fonts (TTF) in assets/fonts folder
  • Pass TypefaceCollection to TypefaceHelper.init() in your Application subclass:
@Override public void onCreate() {
    // Initialize typeface helper
    TypefaceCollection typeface = new TypefaceCollection.Builder()
            .set(Typeface.NORMAL, Typeface.createFromAsset(getAssets(), "fonts/ubuntu/Ubuntu-R.ttf"))
  • Apply custom typefaces to Activity, ViewGroup or View:
@Override protected void onCreate(Bundle savedInstanceState) {
    // Apply custom typefaces!

Advanced usage

Static import for typeface() method

You can use static import for typeface() method:

import static com.norbsoft.typefacehelper.TypefaceHelper.typeface; 

and then use it without referencing TypefaceHelper class:

View v = inflater.inflate(R.layout.myview);

Change font in ActionBar title

Pass ActionBar instance along with SpannableString with custom typeface to ActionBarHelper.setTitle() helper:

    typeface(this, R.string.lorem_ipsum_title));

Apply in AdapterView (ListView, Spinner)

Each time ConvertView is created inside adapter, it needs to be styled via typeface() call

listView.setAdapter(new BaseAdapter() {
    String[] items = { "Item 1", "Item 2", "Item 3" };

    @Override public int getCount() {
        return items.length;
    @Override public Object getItem(int position) {
        return items[position];
    @Override public long getItemId(int position) {
        return items[position].hashCode();
    @Override public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context)
                    .inflate(android.R.layout.simple_list_item_1, parent, false);
            // Apply custom typeface!

        ((TextView) convertView).setText(items[position]);
        return convertView;

Use multiple typefaces and styles

First, define and initialize TypefaceCollection for each typeface you intend to use in your Application subclass:

public class MyApplication extends Application {

    private TypefaceCollection mArchRivalTypeface;
    private TypefaceCollection mUbuntuTypeface;

    @Override public void onCreate() {

        // Initialize Arch Rival typeface
        mArchRivalTypeface = new TypefaceCollection.Builder()
            .set(Typeface.NORMAL, Typeface.createFromAsset(getAssets(), 
            .set(Typeface.BOLD, Typeface.createFromAsset(getAssets(),
            .set(Typeface.ITALIC, Typeface.createFromAsset(getAssets(),
            .set(Typeface.BOLD_ITALIC, Typeface.createFromAsset(getAssets(),

        // Initialize Ubuntu typeface
        mUbuntuTypeface = new TypefaceCollection.Builder()
            .set(Typeface.NORMAL, Typeface.createFromAsset(getAssets(),
            .set(Typeface.BOLD, Typeface.createFromAsset(getAssets(),
            .set(Typeface.ITALIC, Typeface.createFromAsset(getAssets(), 
            .set(Typeface.BOLD_ITALIC, Typeface.createFromAsset(getAssets(),

        // Load helper with default custom typeface (single custom typeface)

    /** Getter for Arch Rival typeface */
    public TypefaceCollection getArchRivalTypeface() {
        return mArchRivalTypeface;

    /** Getter for Ubuntu typeface */
    public TypefaceCollection getUbuntuTypeface() {
        return mUbuntuTypeface;

Then, call typeface() and pass custmo TypefaceCollection:

    ((MyApplication) getApplication()).getArchRivalTypeface());

    ((MyApplication) getApplication()).getUbuntuTypeface());

Change typefaces dynamically

Typeface changes each time typeface() is called - it can be used from onClick() method:

@Override public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btn_font_ubuntu:
            ((MyApplication) getApplication()).getUbuntuTypeface());
    case R.id.btn_font_arch_rival:
            ((MyApplication) getApplication()).getArchRivalTypeface());


Android Typeface Helper is licensed under http://www.apache.org/licenses/LICENSE-2.0