原文链接 AS创建assets文件夹与字体
方法一
// 设置浪漫雅圆字体 字体格式要为ttf
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/lmyy.ttf");
mTv.setTypeface(typeface);
方法二
// 另一种思路
public class CustomTextView extends TextView{
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setTypeface(Typeface tf) {
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/lmyy.ttf");
super.setTypeface(typeface);
}
}
本文介绍了在Android Studio中通过两种方法实现自定义字体的设置过程。第一种方法直接通过Typeface类的createFromAsset静态方法加载字体文件并应用到TextView上;第二种方法则是在自定义的CustomTextView类中覆盖setTypeface方法,同样使用createFromAsset加载字体。
737

被折叠的 条评论
为什么被折叠?



