移動開發----自定義帶有字型的文字
阿新 • • 發佈:2018-12-13
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); } }