Guest User

Untitled

a guest
Sep 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. //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.
  2.  
  3. //Following is a sample class that creates and cache the typeface object:
  4.  
  5. public class TypeFaceProvider {
  6.  
  7. public static final String TYPEFACE_FOLDER = "fonts";
  8. public static final String TYPEFACE_EXTENSION = ".ttf";
  9.  
  10. private static Hashtable<String, Typeface> sTypeFaces = new Hashtable<String, Typeface>(
  11. 4);
  12.  
  13. public static Typeface getTypeFace(Context context, String fileName) {
  14. Typeface tempTypeface = sTypeFaces.get(fileName);
  15.  
  16. if (tempTypeface == null) {
  17. String fontPath = new StringBuilder(TYPEFACE_FOLDER).append('/').append(fileName).append(TYPEFACE_EXTENSION).toString();
  18. tempTypeface = Typeface.createFromAsset(context.getAssets(), fontPath);
  19. sTypeFaces.put(fileName, tempTypeface);
  20. }
  21.  
  22. return tempTypeface;
  23. }
  24. }
Add Comment
Please, Sign In to add comment