I downloaded the ttf font and put it in the assets / fonts folder .. full folder address: app \ src \ main \ assets \ fonts
I pull out in activit:
Typeface myfonts = Typeface.createFromAsset(getAssets(), "fonts/a_AntiqueTitulGr.ttf"); mSelectedItemView.setTypeface(myfonts); It compiles fine, but the application gives an error. Looked at what: "native typeface cannot be made".
Found a solution that a memory leak is possible. How the solution created the class:
public class Utils { private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>(); public static Typeface getTypeFace(Context context, String assetPath) { synchronized (cache) { if (!cache.containsKey(assetPath)) { try { Typeface typeFace = Typeface.createFromAsset(context.getAssets(), assetPath); cache.put(assetPath, typeFace); } catch (Exception e) { Log.e("TypeFaces", "Typeface not loaded."); return null; } } return cache.get(assetPath); } } } And now pulled out like this:
Typeface myfonts = Utils.getTypeFace(this, "fonts/a_BentTitulDcFr.ttf"); mSelectedItemView.setTypeface(myfonts); The error has disappeared. The application has started. But the font does not change. How to solve this problem? Thank.