I need to connect the font in the fragment. When did in activit, it worked.
In the fragment the following line:
Typeface myfonts = Utils.getTypeFace(this, "fonts/a_BentTitulDcFr.ttf");
Further for the necessary text in this fragment I connect myfonts
with the necessary font.
mSelectedItemView2 = (TextView) v.findViewById(R.id.selected_item2); mSelectedItemView2.setTypeface(myfonts);
Code class Utils.java
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); }
Actually it swears at compilation:
Error:(40, 33) error: method getTypeFace in class Utils cannot be applied to given types; required: Context,String found: Fragment2,String reason: actual argument Fragment2 cannot be converted to Context by method invocation conversion
I tried to change Context
to Fragment2
in the Utils
class, but it did not work: I did not find the getAssets()
method.