From 214f9edd2fe20c20e32630e9b5380cc6271c1eb7 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 27 三月 2021 16:51:13 +0800
Subject: [PATCH] 白色背景修改

---
 library-ViewPagerIndicator/src/com/viewpagerindicator/MainTabPageIndicator.java |   44 ++++++++++++++++++++++++++++++++------------
 1 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/library-ViewPagerIndicator/src/com/viewpagerindicator/MainTabPageIndicator.java b/library-ViewPagerIndicator/src/com/viewpagerindicator/MainTabPageIndicator.java
index 8a2e078..6ca7bbe 100644
--- a/library-ViewPagerIndicator/src/com/viewpagerindicator/MainTabPageIndicator.java
+++ b/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,20 @@
 
     private int mMaxTabWidth;
     private int mSelectedTabIndex;
+    private int textColor;
+    private int highLightTextColor;
 
     private OnTabReselectedListener mTabReselectedListener;
 
     public MainTabPageIndicator(Context context) {
         this(context, null);
     }
+
+    public void setTextColor(int textColor, int highLightTextColor) {
+        this.textColor = textColor;
+        this.highLightTextColor = highLightTextColor;
+    }
+
 
     public MainTabPageIndicator(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -143,13 +154,13 @@
             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);
+            ((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 +202,34 @@
     @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) {
+            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

--
Gitblit v1.8.0