gpt4 book ai didi

android - TabPageIndicator 文本字体

转载 作者:太空狗 更新时间:2023-10-29 15:55:01 25 4
gpt4 key购买 nike

我正在使用 ViewPagerIndicator,但没有任何运气,所以我会在这里问一下。有没有办法更改 TabPageIndicator 中选项卡的字体?

最佳答案

您不需要使用其他第三方库来执行此操作,您可以修改 TabView class(in TabPageIndicator)像这样(假设您希望在整个应用程序中使用相同的字体):

private class TabView extends TextView {
private int mIndex;

public TabView(Context context) {
super(context, null, R.attr.vpiTabPageIndicatorStyle);
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

// Re-measure if we went beyond our maximum size.
if (mMaxTabWidth > 0 && getMeasuredWidth() > mMaxTabWidth) {
super.onMeasure(MeasureSpec.makeMeasureSpec(mMaxTabWidth, MeasureSpec.EXACTLY), heightMeasureSpec);
}
}

public int getIndex() {
return mIndex;
}

public TabView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}

public TabView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public TabView(Context context) {
super(context);
init();
}

private void init() {

Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/myFont.ttf"); // setting a custom TypeFace
setTypeface(tf);

}

关于android - TabPageIndicator 文本字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14228186/

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