Created
June 7, 2016 15:38
-
-
Save Komarev/51ff3012e9ba7a80012e5f19795d6a75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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