TabPageIndicator文本字体文本、字体、TabPageIndicator

由网友(久病成欢孤独成瘾)分享简介:我使用ViewPagerIndicator,并没有任何运气,所以我会问这里。有没有办法来改变字体的选项卡中TabPageIndicator? I'm using ViewPagerIndicator, and haven't had any luck, so I'll ask here. Is there a way...

我使用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);

    }
阅读全文

相关推荐

最新文章