From 2eec3de87b6b616a69a46c1f97c2397159031d2f Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 21 十一月 2023 18:01:43 +0800 Subject: [PATCH] 广告升级/bug修复 --- library-ViewPagerIndicator/src/com/viewpagerindicator/MainTabPageIndicator.java | 65 ++++++++++++++++++++++++-------- 1 files changed, 48 insertions(+), 17 deletions(-) diff --git a/library-ViewPagerIndicator/src/com/viewpagerindicator/MainTabPageIndicator.java b/library-ViewPagerIndicator/src/com/viewpagerindicator/MainTabPageIndicator.java index 8a2e078..d34d160 100644 --- a/library-ViewPagerIndicator/src/com/viewpagerindicator/MainTabPageIndicator.java +++ b/library-ViewPagerIndicator/src/com/viewpagerindicator/MainTabPageIndicator.java @@ -21,13 +21,12 @@ import android.annotation.SuppressLint; import android.content.Context; -import android.content.res.Resources; import android.graphics.Color; -import android.support.v4.view.PagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v4.view.ViewPager.OnPageChangeListener; +import android.graphics.Typeface; +import androidx.viewpager.widget.PagerAdapter; +import androidx.viewpager.widget.ViewPager; +import androidx.viewpager.widget.ViewPager.OnPageChangeListener; import android.util.AttributeSet; -import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; import android.widget.HorizontalScrollView; @@ -82,12 +81,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 +158,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 +210,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 -- Gitblit v1.8.0