Last active
September 20, 2018 07:52
-
-
Save achinverma/771a0474747297c5cdbc6824103c26cc 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
//Why don't you keep the created typface object in memory so that you don't create every time the text view is getting created. | |
//Following is a sample class that creates and cache the typeface object: | |
public class TypeFaceProvider { | |
public static final String TYPEFACE_FOLDER = "fonts"; | |
public static final String TYPEFACE_EXTENSION = ".ttf"; | |
private static Hashtable<String, Typeface> sTypeFaces = new Hashtable<String, Typeface>( | |
4); | |
public static Typeface getTypeFace(Context context, String fileName) { | |
Typeface tempTypeface = sTypeFaces.get(fileName); | |
if (tempTypeface == null) { | |
String fontPath = new StringBuilder(TYPEFACE_FOLDER).append('/').append(fileName).append(TYPEFACE_EXTENSION).toString(); | |
tempTypeface = Typeface.createFromAsset(context.getAssets(), fontPath); | |
sTypeFaces.put(fileName, tempTypeface); | |
} | |
return tempTypeface; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment