【发布时间】:2017-02-02 14:15:35
【问题描述】:
我正在尝试使用自定义字体系列创建TextView。我创建了一个支持普通字体的。但我无法在自定义 TextView 上实现 bold/italic 样式。
这是我的自定义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);
}
谁能提出一种实现粗体和斜体样式的方法。
【问题讨论】: