Skip to content

Instantly share code, notes, and snippets.

@ahmedyehya92
Created March 20, 2019 18:31
Show Gist options
  • Save ahmedyehya92/6006f637045ebed53bb15e69e70b4e6b to your computer and use it in GitHub Desktop.
Save ahmedyehya92/6006f637045ebed53bb15e69e70b4e6b to your computer and use it in GitHub Desktop.
FontCache
public class FontCache {
private static Map<String, Typeface> sCachedFonts = new HashMap<String, Typeface>();
public static Typeface getTypeface(String assetPath, Context context ) {
if (!sCachedFonts.containsKey(assetPath)) {
Typeface tf = Typeface.createFromAsset(context.getAssets(), assetPath);
sCachedFonts.put(assetPath, tf);
}
return sCachedFonts.get(assetPath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment