TabPageIndicator文本字体

TabPageIndicator文本字体

本文介绍了TabPageIndicator文本字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ViewPagerIndicator,并没有任何运气,所以我会问这里。有没有办法来改变字体的选项卡中TabPageIndicator?

I'm using ViewPagerIndicator, and haven't had any luck, so I'll ask here. Is there a way to change the font for the Tabs in a TabPageIndicator?

推荐答案

您不必使用其他第三方的lib为了做到这一点,你可以修改 TabView的类(在TabPageIndicator)这样的(这个假设你想的一样的字体在您的整个应用程序):

You don't need to use an other third party lib in order to do this, you can modify the TabView class(in TabPageIndicator) like this(this assuming you want the same font in your entire app):

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);

    }

这篇关于TabPageIndicator文本字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 08:30