2
나는 안드로이드에서 새로운데, 내 애플 리케이션을위한 내 사용자 정의 글꼴을 사용하고 싶습니다. 나는 사용자 정의 글꼴을 만드는 두 가지 방법을 썼다. 어느 것이 더 좋고 더 빠른지 말해 줄 수 있습니까? 첫 번째 방법은 싱글 톤 클래스 두 번째 방법은 내 자신의 textview를 만드는 것입니다. 반면 사용자 정의 텍스트 뷰 방식에서 자신의 텍스트 뷰하나 더 좋은 사용자 정의 글꼴 만들기
public class MyTextView extends TextView {
public MyTextView(Context context) {
super(context);
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setFonts(context,attrs);
}
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setFonts(context,attrs);
}
private void setFonts(Context context, AttributeSet attrs){
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyTextView_customFont);
String ttfName = a.getString(R.styleable.MyTextView_customFont_ttf_name);
setCustomTypeFace(context, ttfName);
}
public void setCustomTypeFace(Context context, String ttfName) {
Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/MuseoSansCyrl_"+ttfName+".otf");
setTypeface(font);
}
@Override
public void setTypeface(Typeface tf) {
super.setTypeface(tf);
}
}