From 4f5993f85caf169b147c47c809e8487a3a403814 Mon Sep 17 00:00:00 2001 From: yuyang Date: Tue, 30 Oct 2018 17:12:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0tl=5FtextSelectSize=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=EF=BC=8C=E8=AE=BE=E7=BD=AE=E9=80=89=E4=B8=AD=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/flyco/tablayout/CommonTabLayout.java | 10 +++++++++- .../java/com/flyco/tablayout/SlidingTabLayout.java | 14 +++++++++++--- FlycoTabLayout_Lib/src/main/res/values/attrs.xml | 5 +++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java b/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java index b0db9cd1..361cd53b 100644 --- a/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java +++ b/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java @@ -88,6 +88,7 @@ public class CommonTabLayout extends FrameLayout implements ValueAnimator.Animat private static final int TEXT_BOLD_WHEN_SELECT = 1; private static final int TEXT_BOLD_BOTH = 2; private float mTextsize; + private float mTextSelectSize; private int mTextSelectColor; private int mTextUnselectColor; private int mTextBold; @@ -172,6 +173,7 @@ private void obtainAttributes(Context context, AttributeSet attrs) { mDividerPadding = ta.getDimension(R.styleable.CommonTabLayout_tl_divider_padding, dp2px(12)); mTextsize = ta.getDimension(R.styleable.CommonTabLayout_tl_textsize, sp2px(13f)); + mTextSelectSize = ta.getDimension(R.styleable.CommonTabLayout_tl_textSelectSize,sp2px(13f)); mTextSelectColor = ta.getColor(R.styleable.CommonTabLayout_tl_textSelectColor, Color.parseColor("#ffffff")); mTextUnselectColor = ta.getColor(R.styleable.CommonTabLayout_tl_textUnselectColor, Color.parseColor("#AAffffff")); mTextBold = ta.getInt(R.styleable.CommonTabLayout_tl_textBold, TEXT_BOLD_NONE); @@ -270,7 +272,7 @@ private void updateTabStyles() { tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0); TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor); - tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize); + tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, i == mCurrentTab ? mTextSelectSize : mTextsize); // tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0); if (mTextAllCaps) { tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase()); @@ -313,6 +315,7 @@ private void updateTabSelection(int position) { final boolean isSelect = i == position; TextView tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); tab_title.setTextColor(isSelect ? mTextSelectColor : mTextUnselectColor); + tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX,isSelect ? mTextSelectSize : mTextsize); ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon); CustomTabEntity tabEntity = mTabEntitys.get(i); iv_tab_icon.setImageResource(isSelect ? tabEntity.getTabSelectedIcon() : tabEntity.getTabUnselectedIcon()); @@ -598,6 +601,11 @@ public void setTextsize(float textsize) { updateTabStyles(); } + public void setTextSelectSize(float textSize){ + this.mTextSelectSize = sp2px(textSize); + updateTabStyles(); + } + public void setTextSelectColor(int textSelectColor) { this.mTextSelectColor = textSelectColor; updateTabStyles(); diff --git a/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java b/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java index 9ab7e5ed..58b7c6ed 100644 --- a/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java +++ b/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java @@ -88,6 +88,7 @@ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager. private static final int TEXT_BOLD_WHEN_SELECT = 1; private static final int TEXT_BOLD_BOTH = 2; private float mTextsize; + private float mTextSelectSize; private int mTextSelectColor; private int mTextUnselectColor; private int mTextBold; @@ -156,6 +157,7 @@ private void obtainAttributes(Context context, AttributeSet attrs) { mDividerPadding = ta.getDimension(R.styleable.SlidingTabLayout_tl_divider_padding, dp2px(12)); mTextsize = ta.getDimension(R.styleable.SlidingTabLayout_tl_textsize, sp2px(14)); + mTextSelectSize = ta.getDimension(R.styleable.SlidingTabLayout_tl_textSelectSize,(sp2px(14))); mTextSelectColor = ta.getColor(R.styleable.SlidingTabLayout_tl_textSelectColor, Color.parseColor("#ffffff")); mTextUnselectColor = ta.getColor(R.styleable.SlidingTabLayout_tl_textUnselectColor, Color.parseColor("#AAffffff")); mTextBold = ta.getInt(R.styleable.SlidingTabLayout_tl_textBold, TEXT_BOLD_NONE); @@ -298,7 +300,7 @@ private void updateTabStyles() { TextView tv_tab_title = (TextView) v.findViewById(R.id.tv_tab_title); if (tv_tab_title != null) { tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor); - tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize); + tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX,i == mCurrentTab ? mTextSelectSize : mTextsize); tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0); if (mTextAllCaps) { tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase()); @@ -369,6 +371,7 @@ private void updateTabSelection(int position) { if (tab_title != null) { tab_title.setTextColor(isSelect ? mTextSelectColor : mTextUnselectColor); + tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX,isSelect ? mTextSelectSize : mTextsize); if (mTextBold == TEXT_BOLD_WHEN_SELECT) { tab_title.getPaint().setFakeBoldText(isSelect); } @@ -386,7 +389,7 @@ private void calcIndicatorRect() { //for mIndicatorWidthEqualTitle if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) { TextView tab_title = (TextView) currentTabView.findViewById(R.id.tv_tab_title); - mTextPaint.setTextSize(mTextsize); + mTextPaint.setTextSize(mTextSelectSize); float textWidth = mTextPaint.measureText(tab_title.getText().toString()); margin = (right - left - textWidth) / 2; } @@ -402,7 +405,7 @@ private void calcIndicatorRect() { //for mIndicatorWidthEqualTitle if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) { TextView next_tab_title = (TextView) nextTabView.findViewById(R.id.tv_tab_title); - mTextPaint.setTextSize(mTextsize); + mTextPaint.setTextSize(mTextSelectSize); float nextTextWidth = mTextPaint.measureText(next_tab_title.getText().toString()); float nextMargin = (nextTabRight - nextTabLeft - nextTextWidth) / 2; margin = margin + mCurrentPositionOffset * (nextMargin - margin); @@ -629,6 +632,11 @@ public void setTextsize(float textsize) { updateTabStyles(); } + public void setTextSelectSize(float textSize){ + this.mTextSelectSize = sp2px(textSize); + updateTabStyles(); + } + public void setTextSelectColor(int textSelectColor) { this.mTextSelectColor = textSelectColor; updateTabStyles(); diff --git a/FlycoTabLayout_Lib/src/main/res/values/attrs.xml b/FlycoTabLayout_Lib/src/main/res/values/attrs.xml index b0afdbee..ffb29910 100644 --- a/FlycoTabLayout_Lib/src/main/res/values/attrs.xml +++ b/FlycoTabLayout_Lib/src/main/res/values/attrs.xml @@ -64,6 +64,8 @@ + + @@ -108,6 +110,7 @@ + @@ -148,6 +151,7 @@ + @@ -197,6 +201,7 @@ +