Skip to content

Instantly share code, notes, and snippets.

@MariusBudin-zz
Last active August 29, 2015 14:26
Show Gist options
  • Save MariusBudin-zz/07083e9f7d3ff7a12381 to your computer and use it in GitHub Desktop.
Save MariusBudin-zz/07083e9f7d3ff7a12381 to your computer and use it in GitHub Desktop.
Creating a Typefont each time you want to create a custom font TextView might impact the performance of your app, this is a one-time lazy loader class for custom text fonts in Android
package com.ics.utils;
import android.content.Context;
import android.graphics.Typeface;
import java.util.HashMap;
import java.util.Map;
/**
* Created by marius on 30/7/15.
*
* A one-time lazy loader class for custom text fonts
*
* @music Epic 45 - We were never here
*/
public class FontLoader {
private static Map<String, Typeface> typefaces = new HashMap<>();
public static Typeface getTypeface(Context context, String font) {
if (!typefaces.containsKey(font)) {
final Typeface typeface = Typeface.createFromAsset(context.getAssets(), font);
typefaces.put(font, typeface);
return typeface;
}
return typefaces.get(font);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment