Android 棒棒糖按钮上的自定义字体
我已经实现了我自己的类,扩展了androidAndroid 棒棒糖按钮上的自定义字体,android,android-layout,android-fonts,Android,Android Layout,Android Fonts,我已经实现了我自己的类,扩展了androidandroid.widget.Button类,以便在我的所有按钮中使用自定义字体。 为了实现这一点,我重写了方法setTypeface,如下所示: public void setTypeface(Typeface tf, int style) { if (!isInEditMode()) { super.setTypeface(Fonts.get(style, getContext())); } } 这在我的应用程序支
android.widget.Button
类,以便在我的所有按钮中使用自定义字体。
为了实现这一点,我重写了方法setTypeface
,如下所示:
public void setTypeface(Typeface tf, int style) {
if (!isInEditMode()) {
super.setTypeface(Fonts.get(style, getContext()));
}
}
这在我的应用程序支持的所有android版本中都非常有效,除了棒棒糖。有人知道我在做什么吗?我弄明白了,我忘了覆盖方法的另一个定义
setTypeface
。所以我得到的最终工作代码是:
@Override
public void setTypeface(Typeface tf) {
if (!isInEditMode()) {
super.setTypeface(Fonts.get(getContext()));
}
}
@Override
public void setTypeface(Typeface tf, int style) {
if (!isInEditMode()) {
super.setTypeface(Fonts.get(style, getContext()));
}
}