Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
private static Typeface arialTypeface;
public static final Typeface Arial(Context ctx) {
if (arialTypeface == null) {
arialTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/arial.ttf");
}
return arialTypeface;
}
public static final HashMap<String, Typeface> sTypefaceCache = new HashMap<String, Typeface>();
public static final Typeface getTypeface(AssetManager mgr, String path) {
if(!sTypefaceCache.containsKey(path)) {
Typeface tf = Typeface.createFromAsset(mgr, path);
sTypefaceCache.put(path, tf);
}
return sTypefaceCache.get(path);
}
public static void applyCustomFont(ViewGroup list, Typeface customTypeface) {
for (int i = 0; i < list.getChildCount(); i++) {
View view = list.getChildAt(i);
if (view instanceof ViewGroup) {
applyCustomFont((ViewGroup) view, customTypeface);
} else if (view instanceof TextView) {
((TextView) view).setTypeface(customTypeface);
}
}
}
Подключение шрифтов в своем проекте