安卓中若要使用自定义字体,一般可以将字体的ttf文件放到assets下面,用方法
Typeface mFont = Typeface.createFromAsset(getAssets(), "Roboto-Thin.ttf");
得到字体文件对应的字体对象。
若要将ViewGroup中的所有字体更换,可使用如下方法:
public void setFont(ViewGroup group, Typeface font) {
int count = group.getChildCount();
View v;
for (int i = 0; i < count; i++) {
v = group.getChildAt(i);
if (v instanceof TextView || v instanceof EditText || v instanceof Button) {
((TextView) v).setTypeface(font);
} else if (v instanceof ViewGroup)
setFont((ViewGroup) v, font);
}
}
该方法用递归的手段查找ViewGroup里的TextView,EditText,Button将其字体改变。