Skip to content

Instantly share code, notes, and snippets.

@hrules6872
Created March 1, 2016 09:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrules6872/ffedd74c07c374f93ef2 to your computer and use it in GitHub Desktop.
Save hrules6872/ffedd74c07c374f93ef2 to your computer and use it in GitHub Desktop.
FontCache
public class FontCache {
private static final Map<String, Typeface> mapFont = new HashMap<>();
public static Typeface getFont(Context context, String fontName) {
Typeface typeface = mapFont.get(fontName);
if (typeface == null) {
try {
typeface = Typeface.createFromAsset(context.getAssets(), fontName);
} catch (Exception e) {
typeface = Typeface.DEFAULT;
}
mapFont.put(fontName, typeface);
}
return typeface;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment