在我的應用程序中,我使用ViewPager和PagerTabStrip,我需要爲我的小部件設置自定義字體。要爲Button
或TextView
設置字體,我只需擴展該類並設置字體。如何將TypeFace設置爲PagerTBStrip文本視圖
public class MyButton extends Button {
public MyButton(Context context) {
super(context);
initCustomFont();
}
public MyButton(Context context, AttributeSet attrs) {
super(context, attrs);
initCustomFont();
}
public MyButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initCustomFont();
}
private void initCustomFont() {
if(!isInEditMode()) {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/boton_regular.ttf");
setTypeface(tf);
}
}
}
但我不能使用這種方法的PagerTabStrip
。是否有另一種方式來設置可與PagerTabStrip
一起使用的字體?
這是醜陋的,但目前爲止可能是最快的解決方案。謝謝=) – ben 2012-12-13 03:13:56
我同意,但我不能想到另一種解決方案,而不是直接抓取源代碼和修改它。沒有支持的API直接更改PagerTabStrip的字體。 – StackOverflower 2013-01-03 21:52:22