Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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;
- }
- }
Add Comment
Please, Sign In to add comment