Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加tl_textSelectSize属性,设置选中字体大小 #372

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions FlycoTabLayout_Lib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
<!-- title -->
<!-- 设置字体大小 -->
<attr name="tl_textsize" format="dimension"/>
<!-- 设置选中字体大小-->
<attr name="tl_textSelectSize" format="dimension"/>
<!-- 设置字体选中颜色 -->
<attr name="tl_textSelectColor" format="color"/>
<!-- 设置字体未选中颜色 -->
Expand Down Expand Up @@ -108,6 +110,7 @@

<!-- title -->
<attr name="tl_textsize"/>
<attr name="tl_textSelectSize"/>
<attr name="tl_textSelectColor"/>
<attr name="tl_textUnselectColor"/>
<attr name="tl_textBold"/>
Expand Down Expand Up @@ -148,6 +151,7 @@

<!-- title -->
<attr name="tl_textsize"/>
<attr name="tl_textSelectSize"/>
<attr name="tl_textSelectColor"/>
<attr name="tl_textUnselectColor"/>
<attr name="tl_textBold"/>
Expand Down Expand Up @@ -197,6 +201,7 @@

<!-- title -->
<attr name="tl_textsize"/>
<attr name="tl_textSelectSize"/>
<attr name="tl_textSelectColor"/>
<attr name="tl_textUnselectColor"/>
<attr name="tl_textBold"/>
Expand Down