Мне нужно подключить шрифт в фрагменте. Когда делал в активити, то работало.
В фрагменте такая строчка:
Typeface myfonts = Utils.getTypeFace(this, "fonts/a_BentTitulDcFr.ttf");
Далее для нужного текста в этом фрагменте я подключаю myfonts
с нужным шрифтом.
mSelectedItemView2 = (TextView) v.findViewById(R.id.selected_item2);
mSelectedItemView2.setTypeface(myfonts);
Код класс 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);
}
Собственно он ругается при компиляции:
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
пытался поменять Context
на Fragment2
в классе Utils
, но не заработало: не нашел метод getAssets()
.