public class GameTextView extends TextView {
private static Typeface typeface;
public GameTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setTypeFace(context);
}
public GameTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setTypeFace(context);
}
public GameTextView(Context context) {
super(context);
setTypeFace(context);
}
private void setTypeFace(Context context) {
if(typeface == null)
//引用assets文件下fonts文件写的字体文件
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/gothic.ttf");
//引用 res /font 字体
// typeFace = ResourcesCompat.getFont(context, R.font.baloo2_bold);
this.setTypeface(typeface);
}
}
移动开发----自定义带有字体的文本
于 2017-07-04 20:43:19 首次发布