admin
2021-04-02 545ce4665c1d506393908b55aafd681a45c774e6
library-ViewPagerIndicator/src/com/viewpagerindicator/MainTabPageIndicator.java
@@ -23,11 +23,14 @@
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
@@ -82,12 +85,28 @@
    private int mMaxTabWidth;
    private int mSelectedTabIndex;
    private int textColor;
    private int highLightTextColor;
    private int textSpecialColorPosition = -1;
    private int textSpecialColor;
    private OnTabReselectedListener mTabReselectedListener;
    public MainTabPageIndicator(Context context) {
        this(context, null);
    }
    public void setTextColor(int textColor, int highLightTextColor) {
        this.textColor = textColor;
        this.highLightTextColor = highLightTextColor;
    }
    public void setTextSpecialColor(int position, int color) {
        this.textSpecialColorPosition = position;
        this.textSpecialColor = color;
    }
    public MainTabPageIndicator(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -143,13 +162,17 @@
            removeCallbacks(mTabSelector);
        }
        for (int i = 0; i < mTabLayout.getChildCount(); i++) {
            ((TextView) mTabLayout.getChildAt(i)).setTextSize(
                    TypedValue.COMPLEX_UNIT_SP, 15);
            ((TextView) mTabLayout.getChildAt(i)).setTextColor(Color.parseColor("#999999"));
            ((TextView) mTabLayout.getChildAt(i)).setTextSize(15);
            if (i == textSpecialColorPosition) {
                ((TextView) mTabLayout.getChildAt(i)).setTextColor(textSpecialColor);
            } else {
                ((TextView) mTabLayout.getChildAt(i)).setTextColor(textColor);
            }
            ((TextView) mTabLayout.getChildAt(i)).setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        }
        ((TextView) tabView).setTextColor(Color.WHITE);
        ((TextView) tabView).setTextSize(
                TypedValue.COMPLEX_UNIT_SP, 20);
        ((TextView) tabView).setTextColor(highLightTextColor);
        ((TextView) tabView).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        ((TextView) tabView).setTextSize(20);
//        ((TextView) tabView).setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT,WRAP_CONTENT));
        mTabSelector = new Runnable() {
            public void run() {
@@ -191,25 +214,37 @@
    @SuppressLint("ResourceAsColor")
    private void addTab(int index, CharSequence text, int iconResId) {
        final TabView tabView = new TabView(getContext());
        tabView.setPadding(0, 0, 0, 0);
        tabView.mIndex = index;
        tabView.setFocusable(true);
        tabView.setOnClickListener(mTabClickListener);
        tabView.setText(text);
        tabView.setTextColor(R.color.black1);
        tabView.setBackgroundResource(R.drawable.found__tab_indicator);
        if (textColor > 0) {
            if (index == textSpecialColorPosition) {
                tabView.setTextColor(textSpecialColor);
            } else
                tabView.setTextColor(textColor);
        } else {
            tabView.setTextColor(R.color.black1);
        }
        tabView.setBackgroundColor(Color.TRANSPARENT);
        if (iconResId != 0) {
            tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
        }
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(WRAP_CONTENT,
                MATCH_PARENT, 1);
                WRAP_CONTENT, 1);
        mTabLayout.addView(tabView, params);
        MarginLayoutParams marginLayoutParams = (MarginLayoutParams) tabView.getLayoutParams();
        if (index == 0)
            marginLayoutParams.leftMargin = DimenUtils.dip2px(getContext(), 10);
        else
            marginLayoutParams.leftMargin = DimenUtils.dip2px(getContext(), 21);
        else {
            marginLayoutParams.leftMargin = DimenUtils.dip2px(getContext(), 13);
        }
        if (index == mTabLayout.getChildCount() - 1) {
            marginLayoutParams.rightMargin = DimenUtils.dip2px(getContext(), 10);
        }
    }
    @Override