get Font from asset - Android App

Android examples for App:Assets

Description

get Font from asset

Demo Code


//package com.java2s;

import android.content.Context;
import android.graphics.Typeface;
import android.support.v4.util.LruCache;

public class Main {
    private static final LruCache<String, Typeface> sTypefaceCache = new LruCache<String, Typeface>(
            12);/* w  w w  .  j a  va  2s.c o m*/

    public static Typeface getFont(Context c, String name) {
        Typeface typeface = sTypefaceCache.get(name);
        if (typeface == null) {
            typeface = Typeface.createFromAsset(c.getApplicationContext()
                    .getAssets(), "fontawesome-webfont.ttf");
            sTypefaceCache.put(name, typeface);
        }
        return sTypefaceCache.get(name);
    }
}

Related Tutorials