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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhanwei0102/article/details/74356788
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);

    }
}

猜你喜欢

转载自blog.csdn.net/zhanwei0102/article/details/74356788