import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
/**
* Created by Administrator on 2016/2/26.
*/
public class TypefaceUtils {
public static void updateTypeface(ViewGroup root, Context context) {
Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/word.TTF");
for (int i = 0; i < root.getChildCount(); i++) {
View child = root.getChildAt(i);
if (child instanceof TextView) {
((TextView) child).setTypeface(typeface);
} else if (child instanceof Button) {
((Button) child).setTypeface(typeface);
} else if (child instanceof EditText) {
((EditText) child).setTypeface(typeface);
}else if(child instanceof ViewGroup){
updateTypeface((ViewGroup)child,context);
}
}
}
}
android设置字体工具类(需要自己先下载ttf文件)
最新推荐文章于 2024-08-09 07:55:52 发布