gpt4 book ai didi

android - 如何将 TypeFace 设置为 PagerTabStrip TextView

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:34:24 26 4
gpt4 key购买 nike

在我的应用程序中,我使用了 ViewPagerPagerTabStrip我需要为我的小部件设置自定义字体。要为 ButtonTextView 设置字体,我只需扩展类并设置字体。

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com