Skip to content

Instantly share code, notes, and snippets.

@Komarev
Created June 7, 2016 15:38
Show Gist options
  • Save Komarev/51ff3012e9ba7a80012e5f19795d6a75 to your computer and use it in GitHub Desktop.
Save Komarev/51ff3012e9ba7a80012e5f19795d6a75 to your computer and use it in GitHub Desktop.
public class Typefaces {
private static final Hashtable<String, Typeface> mCache = new Hashtable<>();
public static Typeface get(Context context, String fontFileName) {
synchronized (mCache) {
if (!mCache.containsKey(fontFileName)) {
try {
mCache.put(fontFileName,
Typeface.createFromAsset(context.getAssets(), fontFileName));
} catch (Exception e) {
e.printStackTrace();
}
}
return mCache.get(fontFileName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment