您的位置:首页 > 移动开发 > Android开发

android设置字体工具类(需要自己先下载ttf文件)

2016-04-19 14:08 926 查看
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);
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: