移动开发----自定义带有字体的文本

来源:互联网 发布:知乎客服电话是多少 编辑:程序博客网 时间:2024/05/18 02:49
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");        this.setTypeface(typeface);    }}

原创粉丝点击