在我的应用程序中,我使用的是带有PagerTabStrip的ViewPager,我需要为我的小部件设置自定义字体。要为Button或TextView设置字体,我只需扩展该类并设置字样。
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一起使用的字体
发布于 2012-11-16 14:53:17
有点晚了,但这里有一个解决方案。获取PagerTabStrip的子视图并检查它是否是TextView的实例。如果是,请设置字体:
for (int i = 0; i < pagerTabStrip.getChildCount(); ++i) {
View nextChild = pagerTabStrip.getChildAt(i);
if (nextChild instanceof TextView) {
TextView textViewToConvert = (TextView) nextChild;
textViewToConvert.setTypeface(PUT_TYPEFACE_HERE)
}
}发布于 2012-08-13 19:54:36
使用Eclipse (在运行应用程序时在中打开Hierarchy View透视图)检查PagerTabStrip,并搜索它的子项。其中一个必须是包含选项卡标题的TextView。获取此TextView并设置其字体。
https://stackoverflow.com/questions/11932820
复制相似问题