作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在我的应用程序中,我使用了 ViewPager用PagerTabStrip我需要为我的小部件设置自定义字体。要为 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
一起使用的字体?
最佳答案
有点晚了,但这是一个解决方案。获取 PagerTabStrip 的 subview 并检查它是否是 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)
}
}
关于android - 如何将 TypeFace 设置为 PagerTabStrip TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11932820/
我是一名优秀的程序员,十分优秀!