Created
March 1, 2016 09:24
-
-
Save hector6872/ffedd74c07c374f93ef2 to your computer and use it in GitHub Desktop.
FontCache
This file contains hidden or 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 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