0
カスタムフォントファミリでTextView
を作成しようとしています。私は通常のフォントをサポートするフォントを作成しました。しかし、太字/italicカスタムでのスタイリングTextView
を実装することができません。太字、標準、イタリック体のカスタムテキストビュー
この私のカスタムTextView
クラス
public class KTextView extends TextView {
public KTextView(Context context) {
super(context);
TypefaceHelper.setTypeface(context, this);
}
public KTextView(Context context, AttributeSet attrs) {
super(context, attrs);
TypefaceHelper.setTypeface(context, this);
}
public KTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypefaceHelper.setTypeface(context, this);
}
}
これは、誰もが太字や斜体のスタイルを実装する方法を提案することができますTypefaceHelper
クラス
public class TypefaceHelper {
private static final String FONT = "AvenirNext-Regular.otf";
private static Typeface typeface = null;
public static void setTypeface(Context context, TextView textView) {
if (typeface == null) {
typeface = Typeface.createFromAsset(context.getAssets(), FONT);
}
textView.setTypeface(typeface);
}
です。
これを参照してください:[実行時のTextViewのスタイルを変更する方法]( http://stackoverflow.com/questions/4630440/how-to-change-a-textviews-style-at-runtime) – FarshidABZ