Repository: H07000223/FlycoTabLayout
Branch: master
Commit: 528fcffe88d5
Files: 51
Total size: 182.2 KB
Directory structure:
gitextract_h399tfmj/
├── .gitignore
├── CHNAGELOG.md
├── FlycoTabLayout_Lib/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ └── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── com/
│ │ └── flyco/
│ │ └── tablayout/
│ │ ├── CommonTabLayout.java
│ │ ├── SegmentTabLayout.java
│ │ ├── SlidingTabLayout.java
│ │ ├── listener/
│ │ │ ├── CustomTabEntity.java
│ │ │ └── OnTabSelectListener.java
│ │ ├── utils/
│ │ │ ├── FragmentChangeManager.java
│ │ │ └── UnreadMsgUtils.java
│ │ └── widget/
│ │ └── MsgView.java
│ └── res/
│ ├── layout/
│ │ ├── layout_tab.xml
│ │ ├── layout_tab_bottom.xml
│ │ ├── layout_tab_left.xml
│ │ ├── layout_tab_right.xml
│ │ ├── layout_tab_segment.xml
│ │ └── layout_tab_top.xml
│ └── values/
│ └── attrs.xml
├── LICENSE
├── README.md
├── README_CN.md
├── app/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ └── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── com/
│ │ └── flyco/
│ │ └── tablayoutsamples/
│ │ ├── adapter/
│ │ │ └── SimpleHomeAdapter.java
│ │ ├── entity/
│ │ │ └── TabEntity.java
│ │ ├── ui/
│ │ │ ├── CommonTabActivity.java
│ │ │ ├── SegmentTabActivity.java
│ │ │ ├── SimpleCardFragment.java
│ │ │ ├── SimpleHomeActivity.java
│ │ │ └── SlidingTabActivity.java
│ │ └── utils/
│ │ └── ViewFindUtils.java
│ └── res/
│ ├── layout/
│ │ ├── activity_common_tab.xml
│ │ ├── activity_segment_tab.xml
│ │ ├── activity_sliding_tab.xml
│ │ └── fr_simple_card.xml
│ └── values/
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── dependencies.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.gradle
/local.properties
build
.idea
*.iml
.DS_Store
================================================
FILE: CHNAGELOG.md
================================================
#Change Log
Version 1.1.2 *(2015-10-14)*
----------------------------
* add method setViewPager(ViewPager vp, String[] titles) for the condition that you do not want set titles in page adapter
Version 1.1.4 *(2015-10-16)*
----------------------------
* fix bug: indicator not show if you do not call viewpager's setCurrentItem method during initialization.
Version 1.1.6 *(2015-10-18)*
----------------------------
* add method setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList<Fragment> fragments)
for the condition that you even do not want to instantiate page adapter by yourself
* add listener OnTabSelectedListener
Version 1.1.8 *(2015-10-19)*
----------------------------
* add block indicator
Version 1.2.0 *(2015-10-20)*
----------------------------
* add unread msg dot (TipView)
Version 1.3.0 *(2015-10-22)*
----------------------------
* new added View: CommonTabLayout is a tablayout without dependence of ViewPager
Version 1.3.2 *(2015-10-28)*
----------------------------
* extract common attributes
Version 1.3.4 *(2015-11-5)*
----------------------------
* replace TipView with RoundTextView
Version 1.3.6 *(2015-11-10)*
----------------------------
* new add attr tl_indicator_width_equal_title
Version 1.4.0 *(2015-11-11)*
----------------------------
* fix bug: attr tl_indicator_width_equal_title sometime invalid
Version 1.4.2 *(2015-12-9)*
----------------------------
* new added tablayout
Version 1.4.4 *(2015-12-11)*
----------------------------
* fix bug: CommonTabLayout first setCurrentTab() cause indicator not show
Version 1.4.6 *(2015-12-11)*
----------------------------
* fix bug: CommonTabLayout first setCurrentTab() cause indicator not show
Version 1.5.0 *(2015-12-11)*
----------------------------
* change code style
Version 2.0.0 *(2016.3.1)*
----------------------------
* remove the dependence of FlycoRoundView
* new added method getIconView and getTitleView
Version 2.0.2 *(2016.4.23)*
----------------------------
* remove the dependence of NineOldAnimation(only support 3.0+)
Version 2.0.6 *(2016.5.21)*
----------------------------
* remove CustomTabProvider in SlidingTabLayout
* new added method 'addNewTab(String title)' for SlidingTabLayout
Version 2.0.8 *(2016.7.26)*
---------------------------
* Fix #27,#31(new added method 'setCurrentTab(int currentTab, boolean smoothScroll)' for SlidingTabLayout and redefine attr 'tl_textBold')
Version 2.1.0 *(2016.10.28)*
----------------------------
* remove Application label in manifest
* add method to make viewpager snap on tab click
Version 2.1.2 *(2017.1.23)*
----------------------------
* update compileSdkVersion to 25, buildToolsVersion to "25.0.2"
Version 3.0.0 *(2021.09.30)*
----------------------------
* AndroidX & publish on Maven Central
================================================
FILE: FlycoTabLayout_Lib/.gitignore
================================================
/build
================================================
FILE: FlycoTabLayout_Lib/build.gradle
================================================
apply plugin: 'com.android.library'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation support.appcompat
implementation support.v4
implementation support.design
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.18.0'
}
}
allprojects {
plugins.withId("com.vanniktech.maven.publish") {
mavenPublish {
sonatypeHost = "S01"
}
}
}
apply plugin: "com.vanniktech.maven.publish"
================================================
FILE: FlycoTabLayout_Lib/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/lihui/work/AndroidStudio/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: FlycoTabLayout_Lib/src/main/AndroidManifest.xml
================================================
<manifest
package="com.flyco.tablayout">
</manifest>
================================================
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java
================================================
package com.flyco.tablayout;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.OvershootInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.flyco.tablayout.utils.FragmentChangeManager;
import com.flyco.tablayout.utils.UnreadMsgUtils;
import com.flyco.tablayout.widget.MsgView;
import java.util.ArrayList;
/** 没有继承HorizontalScrollView不能滑动,对于ViewPager无依赖 */
public class CommonTabLayout extends FrameLayout implements ValueAnimator.AnimatorUpdateListener {
private Context mContext;
private ArrayList<CustomTabEntity> mTabEntitys = new ArrayList<>();
private LinearLayout mTabsContainer;
private int mCurrentTab;
private int mLastTab;
private int mTabCount;
/** 用于绘制显示器 */
private Rect mIndicatorRect = new Rect();
private GradientDrawable mIndicatorDrawable = new GradientDrawable();
private Paint mRectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Paint mDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Paint mTrianglePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Path mTrianglePath = new Path();
private static final int STYLE_NORMAL = 0;
private static final int STYLE_TRIANGLE = 1;
private static final int STYLE_BLOCK = 2;
private int mIndicatorStyle = STYLE_NORMAL;
private float mTabPadding;
private boolean mTabSpaceEqual;
private float mTabWidth;
/** indicator */
private int mIndicatorColor;
private float mIndicatorHeight;
private float mIndicatorWidth;
private float mIndicatorCornerRadius;
private float mIndicatorMarginLeft;
private float mIndicatorMarginTop;
private float mIndicatorMarginRight;
private float mIndicatorMarginBottom;
private long mIndicatorAnimDuration;
private boolean mIndicatorAnimEnable;
private boolean mIndicatorBounceEnable;
private int mIndicatorGravity;
/** underline */
private int mUnderlineColor;
private float mUnderlineHeight;
private int mUnderlineGravity;
/** divider */
private int mDividerColor;
private float mDividerWidth;
private float mDividerPadding;
/** title */
private static final int TEXT_BOLD_NONE = 0;
private static final int TEXT_BOLD_WHEN_SELECT = 1;
private static final int TEXT_BOLD_BOTH = 2;
private float mTextsize;
private int mTextSelectColor;
private int mTextUnselectColor;
private int mTextBold;
private boolean mTextAllCaps;
/** icon */
private boolean mIconVisible;
private int mIconGravity;
private float mIconWidth;
private float mIconHeight;
private float mIconMargin;
private int mHeight;
/** anim */
private ValueAnimator mValueAnimator;
private OvershootInterpolator mInterpolator = new OvershootInterpolator(1.5f);
private FragmentChangeManager mFragmentChangeManager;
public CommonTabLayout(Context context) {
this(context, null, 0);
}
public CommonTabLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CommonTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setWillNotDraw(false);//重写onDraw方法,需要调用这个方法来清除flag
setClipChildren(false);
setClipToPadding(false);
this.mContext = context;
mTabsContainer = new LinearLayout(context);
addView(mTabsContainer);
obtainAttributes(context, attrs);
//get layout_height
String height = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_height");
//create ViewPager
if (height.equals(ViewGroup.LayoutParams.MATCH_PARENT + "")) {
} else if (height.equals(ViewGroup.LayoutParams.WRAP_CONTENT + "")) {
} else {
int[] systemAttrs = {android.R.attr.layout_height};
TypedArray a = context.obtainStyledAttributes(attrs, systemAttrs);
mHeight = a.getDimensionPixelSize(0, ViewGroup.LayoutParams.WRAP_CONTENT);
a.recycle();
}
mValueAnimator = ValueAnimator.ofObject(new PointEvaluator(), mLastP, mCurrentP);
mValueAnimator.addUpdateListener(this);
}
private void obtainAttributes(Context context, AttributeSet attrs) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CommonTabLayout);
mIndicatorStyle = ta.getInt(R.styleable.CommonTabLayout_tl_indicator_style, 0);
mIndicatorColor = ta.getColor(R.styleable.CommonTabLayout_tl_indicator_color, Color.parseColor(mIndicatorStyle == STYLE_BLOCK ? "#4B6A87" : "#ffffff"));
mIndicatorHeight = ta.getDimension(R.styleable.CommonTabLayout_tl_indicator_height,
dp2px(mIndicatorStyle == STYLE_TRIANGLE ? 4 : (mIndicatorStyle == STYLE_BLOCK ? -1 : 2)));
mIndicatorWidth = ta.getDimension(R.styleable.CommonTabLayout_tl_indicator_width, dp2px(mIndicatorStyle == STYLE_TRIANGLE ? 10 : -1));
mIndicatorCornerRadius = ta.getDimension(R.styleable.CommonTabLayout_tl_indicator_corner_radius, dp2px(mIndicatorStyle == STYLE_BLOCK ? -1 : 0));
mIndicatorMarginLeft = ta.getDimension(R.styleable.CommonTabLayout_tl_indicator_margin_left, dp2px(0));
mIndicatorMarginTop = ta.getDimension(R.styleable.CommonTabLayout_tl_indicator_margin_top, dp2px(mIndicatorStyle == STYLE_BLOCK ? 7 : 0));
mIndicatorMarginRight = ta.getDimension(R.styleable.CommonTabLayout_tl_indicator_margin_right, dp2px(0));
mIndicatorMarginBottom = ta.getDimension(R.styleable.CommonTabLayout_tl_indicator_margin_bottom, dp2px(mIndicatorStyle == STYLE_BLOCK ? 7 : 0));
mIndicatorAnimEnable = ta.getBoolean(R.styleable.CommonTabLayout_tl_indicator_anim_enable, true);
mIndicatorBounceEnable = ta.getBoolean(R.styleable.CommonTabLayout_tl_indicator_bounce_enable, true);
mIndicatorAnimDuration = ta.getInt(R.styleable.CommonTabLayout_tl_indicator_anim_duration, -1);
mIndicatorGravity = ta.getInt(R.styleable.CommonTabLayout_tl_indicator_gravity, Gravity.BOTTOM);
mUnderlineColor = ta.getColor(R.styleable.CommonTabLayout_tl_underline_color, Color.parseColor("#ffffff"));
mUnderlineHeight = ta.getDimension(R.styleable.CommonTabLayout_tl_underline_height, dp2px(0));
mUnderlineGravity = ta.getInt(R.styleable.CommonTabLayout_tl_underline_gravity, Gravity.BOTTOM);
mDividerColor = ta.getColor(R.styleable.CommonTabLayout_tl_divider_color, Color.parseColor("#ffffff"));
mDividerWidth = ta.getDimension(R.styleable.CommonTabLayout_tl_divider_width, dp2px(0));
mDividerPadding = ta.getDimension(R.styleable.CommonTabLayout_tl_divider_padding, dp2px(12));
mTextsize = ta.getDimension(R.styleable.CommonTabLayout_tl_textsize, 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);
mTextAllCaps = ta.getBoolean(R.styleable.CommonTabLayout_tl_textAllCaps, false);
mIconVisible = ta.getBoolean(R.styleable.CommonTabLayout_tl_iconVisible, true);
mIconGravity = ta.getInt(R.styleable.CommonTabLayout_tl_iconGravity, Gravity.TOP);
mIconWidth = ta.getDimension(R.styleable.CommonTabLayout_tl_iconWidth, dp2px(0));
mIconHeight = ta.getDimension(R.styleable.CommonTabLayout_tl_iconHeight, dp2px(0));
mIconMargin = ta.getDimension(R.styleable.CommonTabLayout_tl_iconMargin, dp2px(2.5f));
mTabSpaceEqual = ta.getBoolean(R.styleable.CommonTabLayout_tl_tab_space_equal, true);
mTabWidth = ta.getDimension(R.styleable.CommonTabLayout_tl_tab_width, dp2px(-1));
mTabPadding = ta.getDimension(R.styleable.CommonTabLayout_tl_tab_padding, mTabSpaceEqual || mTabWidth > 0 ? dp2px(0) : dp2px(10));
ta.recycle();
}
public void setTabData(ArrayList<CustomTabEntity> tabEntitys) {
if (tabEntitys == null || tabEntitys.size() == 0) {
throw new IllegalStateException("TabEntitys can not be NULL or EMPTY !");
}
this.mTabEntitys.clear();
this.mTabEntitys.addAll(tabEntitys);
notifyDataSetChanged();
}
/** 关联数据支持同时切换fragments */
public void setTabData(ArrayList<CustomTabEntity> tabEntitys, FragmentActivity fa, int containerViewId, ArrayList<Fragment> fragments) {
mFragmentChangeManager = new FragmentChangeManager(fa.getSupportFragmentManager(), containerViewId, fragments);
setTabData(tabEntitys);
}
/** 更新数据 */
public void notifyDataSetChanged() {
mTabsContainer.removeAllViews();
this.mTabCount = mTabEntitys.size();
View tabView;
for (int i = 0; i < mTabCount; i++) {
if (mIconGravity == Gravity.LEFT) {
tabView = View.inflate(mContext, R.layout.layout_tab_left, null);
} else if (mIconGravity == Gravity.RIGHT) {
tabView = View.inflate(mContext, R.layout.layout_tab_right, null);
} else if (mIconGravity == Gravity.BOTTOM) {
tabView = View.inflate(mContext, R.layout.layout_tab_bottom, null);
} else {
tabView = View.inflate(mContext, R.layout.layout_tab_top, null);
}
tabView.setTag(i);
addTab(i, tabView);
}
updateTabStyles();
}
/** 创建并添加tab */
private void addTab(final int position, View tabView) {
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
tv_tab_title.setText(mTabEntitys.get(position).getTabTitle());
ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon);
iv_tab_icon.setImageResource(mTabEntitys.get(position).getTabUnselectedIcon());
tabView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int position = (Integer) v.getTag();
if (mCurrentTab != position) {
setCurrentTab(position);
if (mListener != null) {
mListener.onTabSelect(position);
}
} else {
if (mListener != null) {
mListener.onTabReselect(position);
}
}
}
});
/** 每一个Tab的布局参数 */
LinearLayout.LayoutParams lp_tab = mTabSpaceEqual ?
new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f) :
new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
if (mTabWidth > 0) {
lp_tab = new LinearLayout.LayoutParams((int) mTabWidth, LayoutParams.MATCH_PARENT);
}
mTabsContainer.addView(tabView, position, lp_tab);
}
private void updateTabStyles() {
for (int i = 0; i < mTabCount; i++) {
View tabView = mTabsContainer.getChildAt(i);
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.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
if (mTextAllCaps) {
tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
}
if (mTextBold == TEXT_BOLD_BOTH) {
tv_tab_title.getPaint().setFakeBoldText(true);
} else if (mTextBold == TEXT_BOLD_NONE) {
tv_tab_title.getPaint().setFakeBoldText(false);
}
ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon);
if (mIconVisible) {
iv_tab_icon.setVisibility(View.VISIBLE);
CustomTabEntity tabEntity = mTabEntitys.get(i);
iv_tab_icon.setImageResource(i == mCurrentTab ? tabEntity.getTabSelectedIcon() : tabEntity.getTabUnselectedIcon());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
mIconWidth <= 0 ? LinearLayout.LayoutParams.WRAP_CONTENT : (int) mIconWidth,
mIconHeight <= 0 ? LinearLayout.LayoutParams.WRAP_CONTENT : (int) mIconHeight);
if (mIconGravity == Gravity.LEFT) {
lp.rightMargin = (int) mIconMargin;
} else if (mIconGravity == Gravity.RIGHT) {
lp.leftMargin = (int) mIconMargin;
} else if (mIconGravity == Gravity.BOTTOM) {
lp.topMargin = (int) mIconMargin;
} else {
lp.bottomMargin = (int) mIconMargin;
}
iv_tab_icon.setLayoutParams(lp);
} else {
iv_tab_icon.setVisibility(View.GONE);
}
}
}
private void updateTabSelection(int position) {
for (int i = 0; i < mTabCount; ++i) {
View tabView = mTabsContainer.getChildAt(i);
final boolean isSelect = i == position;
TextView tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
tab_title.setTextColor(isSelect ? mTextSelectColor : mTextUnselectColor);
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());
if (mTextBold == TEXT_BOLD_WHEN_SELECT) {
tab_title.getPaint().setFakeBoldText(isSelect);
}
}
}
private void calcOffset() {
final View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab);
mCurrentP.left = currentTabView.getLeft();
mCurrentP.right = currentTabView.getRight();
final View lastTabView = mTabsContainer.getChildAt(this.mLastTab);
mLastP.left = lastTabView.getLeft();
mLastP.right = lastTabView.getRight();
// Log.d("AAA", "mLastP--->" + mLastP.left + "&" + mLastP.right);
// Log.d("AAA", "mCurrentP--->" + mCurrentP.left + "&" + mCurrentP.right);
if (mLastP.left == mCurrentP.left && mLastP.right == mCurrentP.right) {
invalidate();
} else {
mValueAnimator.setObjectValues(mLastP, mCurrentP);
if (mIndicatorBounceEnable) {
mValueAnimator.setInterpolator(mInterpolator);
}
if (mIndicatorAnimDuration < 0) {
mIndicatorAnimDuration = mIndicatorBounceEnable ? 500 : 250;
}
mValueAnimator.setDuration(mIndicatorAnimDuration);
mValueAnimator.start();
}
}
private void calcIndicatorRect() {
View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab);
float left = currentTabView.getLeft();
float right = currentTabView.getRight();
mIndicatorRect.left = (int) left;
mIndicatorRect.right = (int) right;
if (mIndicatorWidth < 0) { //indicatorWidth小于0时,原jpardogo's PagerSlidingTabStrip
} else {//indicatorWidth大于0时,圆角矩形以及三角形
float indicatorLeft = currentTabView.getLeft() + (currentTabView.getWidth() - mIndicatorWidth) / 2;
mIndicatorRect.left = (int) indicatorLeft;
mIndicatorRect.right = (int) (mIndicatorRect.left + mIndicatorWidth);
}
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab);
IndicatorPoint p = (IndicatorPoint) animation.getAnimatedValue();
mIndicatorRect.left = (int) p.left;
mIndicatorRect.right = (int) p.right;
if (mIndicatorWidth < 0) { //indicatorWidth小于0时,原jpardogo's PagerSlidingTabStrip
} else {//indicatorWidth大于0时,圆角矩形以及三角形
float indicatorLeft = p.left + (currentTabView.getWidth() - mIndicatorWidth) / 2;
mIndicatorRect.left = (int) indicatorLeft;
mIndicatorRect.right = (int) (mIndicatorRect.left + mIndicatorWidth);
}
invalidate();
}
private boolean mIsFirstDraw = true;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode() || mTabCount <= 0) {
return;
}
int height = getHeight();
int paddingLeft = getPaddingLeft();
// draw divider
if (mDividerWidth > 0) {
mDividerPaint.setStrokeWidth(mDividerWidth);
mDividerPaint.setColor(mDividerColor);
for (int i = 0; i < mTabCount - 1; i++) {
View tab = mTabsContainer.getChildAt(i);
canvas.drawLine(paddingLeft + tab.getRight(), mDividerPadding, paddingLeft + tab.getRight(), height - mDividerPadding, mDividerPaint);
}
}
// draw underline
if (mUnderlineHeight > 0) {
mRectPaint.setColor(mUnderlineColor);
if (mUnderlineGravity == Gravity.BOTTOM) {
canvas.drawRect(paddingLeft, height - mUnderlineHeight, mTabsContainer.getWidth() + paddingLeft, height, mRectPaint);
} else {
canvas.drawRect(paddingLeft, 0, mTabsContainer.getWidth() + paddingLeft, mUnderlineHeight, mRectPaint);
}
}
//draw indicator line
if (mIndicatorAnimEnable) {
if (mIsFirstDraw) {
mIsFirstDraw = false;
calcIndicatorRect();
}
} else {
calcIndicatorRect();
}
if (mIndicatorStyle == STYLE_TRIANGLE) {
if (mIndicatorHeight > 0) {
mTrianglePaint.setColor(mIndicatorColor);
mTrianglePath.reset();
mTrianglePath.moveTo(paddingLeft + mIndicatorRect.left, height);
mTrianglePath.lineTo(paddingLeft + mIndicatorRect.left / 2 + mIndicatorRect.right / 2, height - mIndicatorHeight);
mTrianglePath.lineTo(paddingLeft + mIndicatorRect.right, height);
mTrianglePath.close();
canvas.drawPath(mTrianglePath, mTrianglePaint);
}
} else if (mIndicatorStyle == STYLE_BLOCK) {
if (mIndicatorHeight < 0) {
mIndicatorHeight = height - mIndicatorMarginTop - mIndicatorMarginBottom;
} else {
}
if (mIndicatorHeight > 0) {
if (mIndicatorCornerRadius < 0 || mIndicatorCornerRadius > mIndicatorHeight / 2) {
mIndicatorCornerRadius = mIndicatorHeight / 2;
}
mIndicatorDrawable.setColor(mIndicatorColor);
mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left,
(int) mIndicatorMarginTop, (int) (paddingLeft + mIndicatorRect.right - mIndicatorMarginRight),
(int) (mIndicatorMarginTop + mIndicatorHeight));
mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius);
mIndicatorDrawable.draw(canvas);
}
} else {
/* mRectPaint.setColor(mIndicatorColor);
calcIndicatorRect();
canvas.drawRect(getPaddingLeft() + mIndicatorRect.left, getHeight() - mIndicatorHeight,
mIndicatorRect.right + getPaddingLeft(), getHeight(), mRectPaint);*/
if (mIndicatorHeight > 0) {
mIndicatorDrawable.setColor(mIndicatorColor);
if (mIndicatorGravity == Gravity.BOTTOM) {
mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left,
height - (int) mIndicatorHeight - (int) mIndicatorMarginBottom,
paddingLeft + mIndicatorRect.right - (int) mIndicatorMarginRight,
height - (int) mIndicatorMarginBottom);
} else {
mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left,
(int) mIndicatorMarginTop,
paddingLeft + mIndicatorRect.right - (int) mIndicatorMarginRight,
(int) mIndicatorHeight + (int) mIndicatorMarginTop);
}
mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius);
mIndicatorDrawable.draw(canvas);
}
}
}
//setter and getter
public void setCurrentTab(int currentTab) {
mLastTab = this.mCurrentTab;
this.mCurrentTab = currentTab;
updateTabSelection(currentTab);
if (mFragmentChangeManager != null) {
mFragmentChangeManager.setFragments(currentTab);
}
if (mIndicatorAnimEnable) {
calcOffset();
} else {
invalidate();
}
}
public void setIndicatorStyle(int indicatorStyle) {
this.mIndicatorStyle = indicatorStyle;
invalidate();
}
public void setTabPadding(float tabPadding) {
this.mTabPadding = dp2px(tabPadding);
updateTabStyles();
}
public void setTabSpaceEqual(boolean tabSpaceEqual) {
this.mTabSpaceEqual = tabSpaceEqual;
updateTabStyles();
}
public void setTabWidth(float tabWidth) {
this.mTabWidth = dp2px(tabWidth);
updateTabStyles();
}
public void setIndicatorColor(int indicatorColor) {
this.mIndicatorColor = indicatorColor;
invalidate();
}
public void setIndicatorHeight(float indicatorHeight) {
this.mIndicatorHeight = dp2px(indicatorHeight);
invalidate();
}
public void setIndicatorWidth(float indicatorWidth) {
this.mIndicatorWidth = dp2px(indicatorWidth);
invalidate();
}
public void setIndicatorCornerRadius(float indicatorCornerRadius) {
this.mIndicatorCornerRadius = dp2px(indicatorCornerRadius);
invalidate();
}
public void setIndicatorGravity(int indicatorGravity) {
this.mIndicatorGravity = indicatorGravity;
invalidate();
}
public void setIndicatorMargin(float indicatorMarginLeft, float indicatorMarginTop,
float indicatorMarginRight, float indicatorMarginBottom) {
this.mIndicatorMarginLeft = dp2px(indicatorMarginLeft);
this.mIndicatorMarginTop = dp2px(indicatorMarginTop);
this.mIndicatorMarginRight = dp2px(indicatorMarginRight);
this.mIndicatorMarginBottom = dp2px(indicatorMarginBottom);
invalidate();
}
public void setIndicatorAnimDuration(long indicatorAnimDuration) {
this.mIndicatorAnimDuration = indicatorAnimDuration;
}
public void setIndicatorAnimEnable(boolean indicatorAnimEnable) {
this.mIndicatorAnimEnable = indicatorAnimEnable;
}
public void setIndicatorBounceEnable(boolean indicatorBounceEnable) {
this.mIndicatorBounceEnable = indicatorBounceEnable;
}
public void setUnderlineColor(int underlineColor) {
this.mUnderlineColor = underlineColor;
invalidate();
}
public void setUnderlineHeight(float underlineHeight) {
this.mUnderlineHeight = dp2px(underlineHeight);
invalidate();
}
public void setUnderlineGravity(int underlineGravity) {
this.mUnderlineGravity = underlineGravity;
invalidate();
}
public void setDividerColor(int dividerColor) {
this.mDividerColor = dividerColor;
invalidate();
}
public void setDividerWidth(float dividerWidth) {
this.mDividerWidth = dp2px(dividerWidth);
invalidate();
}
public void setDividerPadding(float dividerPadding) {
this.mDividerPadding = dp2px(dividerPadding);
invalidate();
}
public void setTextsize(float textsize) {
this.mTextsize = sp2px(textsize);
updateTabStyles();
}
public void setTextSelectColor(int textSelectColor) {
this.mTextSelectColor = textSelectColor;
updateTabStyles();
}
public void setTextUnselectColor(int textUnselectColor) {
this.mTextUnselectColor = textUnselectColor;
updateTabStyles();
}
public void setTextBold(int textBold) {
this.mTextBold = textBold;
updateTabStyles();
}
public void setIconVisible(boolean iconVisible) {
this.mIconVisible = iconVisible;
updateTabStyles();
}
public void setIconGravity(int iconGravity) {
this.mIconGravity = iconGravity;
notifyDataSetChanged();
}
public void setIconWidth(float iconWidth) {
this.mIconWidth = dp2px(iconWidth);
updateTabStyles();
}
public void setIconHeight(float iconHeight) {
this.mIconHeight = dp2px(iconHeight);
updateTabStyles();
}
public void setIconMargin(float iconMargin) {
this.mIconMargin = dp2px(iconMargin);
updateTabStyles();
}
public void setTextAllCaps(boolean textAllCaps) {
this.mTextAllCaps = textAllCaps;
updateTabStyles();
}
public int getTabCount() {
return mTabCount;
}
public int getCurrentTab() {
return mCurrentTab;
}
public int getIndicatorStyle() {
return mIndicatorStyle;
}
public float getTabPadding() {
return mTabPadding;
}
public boolean isTabSpaceEqual() {
return mTabSpaceEqual;
}
public float getTabWidth() {
return mTabWidth;
}
public int getIndicatorColor() {
return mIndicatorColor;
}
public float getIndicatorHeight() {
return mIndicatorHeight;
}
public float getIndicatorWidth() {
return mIndicatorWidth;
}
public float getIndicatorCornerRadius() {
return mIndicatorCornerRadius;
}
public float getIndicatorMarginLeft() {
return mIndicatorMarginLeft;
}
public float getIndicatorMarginTop() {
return mIndicatorMarginTop;
}
public float getIndicatorMarginRight() {
return mIndicatorMarginRight;
}
public float getIndicatorMarginBottom() {
return mIndicatorMarginBottom;
}
public long getIndicatorAnimDuration() {
return mIndicatorAnimDuration;
}
public boolean isIndicatorAnimEnable() {
return mIndicatorAnimEnable;
}
public boolean isIndicatorBounceEnable() {
return mIndicatorBounceEnable;
}
public int getUnderlineColor() {
return mUnderlineColor;
}
public float getUnderlineHeight() {
return mUnderlineHeight;
}
public int getDividerColor() {
return mDividerColor;
}
public float getDividerWidth() {
return mDividerWidth;
}
public float getDividerPadding() {
return mDividerPadding;
}
public float getTextsize() {
return mTextsize;
}
public int getTextSelectColor() {
return mTextSelectColor;
}
public int getTextUnselectColor() {
return mTextUnselectColor;
}
public int getTextBold() {
return mTextBold;
}
public boolean isTextAllCaps() {
return mTextAllCaps;
}
public int getIconGravity() {
return mIconGravity;
}
public float getIconWidth() {
return mIconWidth;
}
public float getIconHeight() {
return mIconHeight;
}
public float getIconMargin() {
return mIconMargin;
}
public boolean isIconVisible() {
return mIconVisible;
}
public ImageView getIconView(int tab) {
View tabView = mTabsContainer.getChildAt(tab);
ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon);
return iv_tab_icon;
}
public TextView getTitleView(int tab) {
View tabView = mTabsContainer.getChildAt(tab);
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
return tv_tab_title;
}
//setter and getter
// show MsgTipView
private Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private SparseArray<Boolean> mInitSetMap = new SparseArray<>();
/**
* 显示未读消息
*
* @param position 显示tab位置
* @param num num小于等于0显示红点,num大于0显示数字
*/
public void showMsg(int position, int num) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
if (tipView != null) {
UnreadMsgUtils.show(tipView, num);
if (mInitSetMap.get(position) != null && mInitSetMap.get(position)) {
return;
}
if (!mIconVisible) {
setMsgMargin(position, 2, 2);
} else {
setMsgMargin(position, 0,
mIconGravity == Gravity.LEFT || mIconGravity == Gravity.RIGHT ? 4 : 0);
}
mInitSetMap.put(position, true);
}
}
/**
* 显示未读红点
*
* @param position 显示tab位置
*/
public void showDot(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
showMsg(position, 0);
}
public void hideMsg(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
if (tipView != null) {
tipView.setVisibility(View.GONE);
}
}
/**
* 设置提示红点偏移,注意
* 1.控件为固定高度:参照点为tab内容的右上角
* 2.控件高度不固定(WRAP_CONTENT):参照点为tab内容的右上角,此时高度已是红点的最高显示范围,所以这时bottomPadding其实就是topPadding
*/
public void setMsgMargin(int position, float leftPadding, float bottomPadding) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
if (tipView != null) {
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
mTextPaint.setTextSize(mTextsize);
float textWidth = mTextPaint.measureText(tv_tab_title.getText().toString());
float textHeight = mTextPaint.descent() - mTextPaint.ascent();
MarginLayoutParams lp = (MarginLayoutParams) tipView.getLayoutParams();
float iconH = mIconHeight;
float margin = 0;
if (mIconVisible) {
if (iconH <= 0) {
iconH = mContext.getResources().getDrawable(mTabEntitys.get(position).getTabSelectedIcon()).getIntrinsicHeight();
}
margin = mIconMargin;
}
if (mIconGravity == Gravity.TOP || mIconGravity == Gravity.BOTTOM) {
lp.leftMargin = dp2px(leftPadding);
lp.topMargin = mHeight > 0 ? (int) (mHeight - textHeight - iconH - margin) / 2 - dp2px(bottomPadding) : dp2px(bottomPadding);
} else {
lp.leftMargin = dp2px(leftPadding);
lp.topMargin = mHeight > 0 ? (int) (mHeight - Math.max(textHeight, iconH)) / 2 - dp2px(bottomPadding) : dp2px(bottomPadding);
}
tipView.setLayoutParams(lp);
}
}
/** 当前类只提供了少许设置未读消息属性的方法,可以通过该方法获取MsgView对象从而各种设置 */
public MsgView getMsgView(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
return tipView;
}
private OnTabSelectListener mListener;
public void setOnTabSelectListener(OnTabSelectListener listener) {
this.mListener = listener;
}
@Override
protected Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putParcelable("instanceState", super.onSaveInstanceState());
bundle.putInt("mCurrentTab", mCurrentTab);
return bundle;
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
mCurrentTab = bundle.getInt("mCurrentTab");
state = bundle.getParcelable("instanceState");
if (mCurrentTab != 0 && mTabsContainer.getChildCount() > 0) {
updateTabSelection(mCurrentTab);
}
}
super.onRestoreInstanceState(state);
}
class IndicatorPoint {
public float left;
public float right;
}
private IndicatorPoint mCurrentP = new IndicatorPoint();
private IndicatorPoint mLastP = new IndicatorPoint();
class PointEvaluator implements TypeEvaluator<IndicatorPoint> {
@Override
public IndicatorPoint evaluate(float fraction, IndicatorPoint startValue, IndicatorPoint endValue) {
float left = startValue.left + fraction * (endValue.left - startValue.left);
float right = startValue.right + fraction * (endValue.right - startValue.right);
IndicatorPoint point = new IndicatorPoint();
point.left = left;
point.right = right;
return point;
}
}
protected int dp2px(float dp) {
final float scale = mContext.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
protected int sp2px(float sp) {
final float scale = this.mContext.getResources().getDisplayMetrics().scaledDensity;
return (int) (sp * scale + 0.5f);
}
}
================================================
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SegmentTabLayout.java
================================================
package com.flyco.tablayout;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.OvershootInterpolator;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.flyco.tablayout.utils.FragmentChangeManager;
import com.flyco.tablayout.utils.UnreadMsgUtils;
import com.flyco.tablayout.widget.MsgView;
import java.util.ArrayList;
public class SegmentTabLayout extends FrameLayout implements ValueAnimator.AnimatorUpdateListener {
private Context mContext;
private String[] mTitles;
private LinearLayout mTabsContainer;
private int mCurrentTab;
private int mLastTab;
private int mTabCount;
/** 用于绘制显示器 */
private Rect mIndicatorRect = new Rect();
private GradientDrawable mIndicatorDrawable = new GradientDrawable();
private GradientDrawable mRectDrawable = new GradientDrawable();
private Paint mDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private float mTabPadding;
private boolean mTabSpaceEqual;
private float mTabWidth;
/** indicator */
private int mIndicatorColor;
private float mIndicatorHeight;
private float mIndicatorCornerRadius;
private float mIndicatorMarginLeft;
private float mIndicatorMarginTop;
private float mIndicatorMarginRight;
private float mIndicatorMarginBottom;
private long mIndicatorAnimDuration;
private boolean mIndicatorAnimEnable;
private boolean mIndicatorBounceEnable;
/** divider */
private int mDividerColor;
private float mDividerWidth;
private float mDividerPadding;
/** title */
private static final int TEXT_BOLD_NONE = 0;
private static final int TEXT_BOLD_WHEN_SELECT = 1;
private static final int TEXT_BOLD_BOTH = 2;
private float mTextsize;
private int mTextSelectColor;
private int mTextUnselectColor;
private int mTextBold;
private boolean mTextAllCaps;
private int mBarColor;
private int mBarStrokeColor;
private float mBarStrokeWidth;
private int mHeight;
/** anim */
private ValueAnimator mValueAnimator;
private OvershootInterpolator mInterpolator = new OvershootInterpolator(0.8f);
private FragmentChangeManager mFragmentChangeManager;
private float[] mRadiusArr = new float[8];
public SegmentTabLayout(Context context) {
this(context, null, 0);
}
public SegmentTabLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SegmentTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setWillNotDraw(false);//重写onDraw方法,需要调用这个方法来清除flag
setClipChildren(false);
setClipToPadding(false);
this.mContext = context;
mTabsContainer = new LinearLayout(context);
addView(mTabsContainer);
obtainAttributes(context, attrs);
//get layout_height
String height = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_height");
//create ViewPager
if (height.equals(ViewGroup.LayoutParams.MATCH_PARENT + "")) {
} else if (height.equals(ViewGroup.LayoutParams.WRAP_CONTENT + "")) {
} else {
int[] systemAttrs = {android.R.attr.layout_height};
TypedArray a = context.obtainStyledAttributes(attrs, systemAttrs);
mHeight = a.getDimensionPixelSize(0, ViewGroup.LayoutParams.WRAP_CONTENT);
a.recycle();
}
mValueAnimator = ValueAnimator.ofObject(new PointEvaluator(), mLastP, mCurrentP);
mValueAnimator.addUpdateListener(this);
}
private void obtainAttributes(Context context, AttributeSet attrs) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SegmentTabLayout);
mIndicatorColor = ta.getColor(R.styleable.SegmentTabLayout_tl_indicator_color, Color.parseColor("#222831"));
mIndicatorHeight = ta.getDimension(R.styleable.SegmentTabLayout_tl_indicator_height, -1);
mIndicatorCornerRadius = ta.getDimension(R.styleable.SegmentTabLayout_tl_indicator_corner_radius, -1);
mIndicatorMarginLeft = ta.getDimension(R.styleable.SegmentTabLayout_tl_indicator_margin_left, dp2px(0));
mIndicatorMarginTop = ta.getDimension(R.styleable.SegmentTabLayout_tl_indicator_margin_top, 0);
mIndicatorMarginRight = ta.getDimension(R.styleable.SegmentTabLayout_tl_indicator_margin_right, dp2px(0));
mIndicatorMarginBottom = ta.getDimension(R.styleable.SegmentTabLayout_tl_indicator_margin_bottom, 0);
mIndicatorAnimEnable = ta.getBoolean(R.styleable.SegmentTabLayout_tl_indicator_anim_enable, false);
mIndicatorBounceEnable = ta.getBoolean(R.styleable.SegmentTabLayout_tl_indicator_bounce_enable, true);
mIndicatorAnimDuration = ta.getInt(R.styleable.SegmentTabLayout_tl_indicator_anim_duration, -1);
mDividerColor = ta.getColor(R.styleable.SegmentTabLayout_tl_divider_color, mIndicatorColor);
mDividerWidth = ta.getDimension(R.styleable.SegmentTabLayout_tl_divider_width, dp2px(1));
mDividerPadding = ta.getDimension(R.styleable.SegmentTabLayout_tl_divider_padding, 0);
mTextsize = ta.getDimension(R.styleable.SegmentTabLayout_tl_textsize, sp2px(13f));
mTextSelectColor = ta.getColor(R.styleable.SegmentTabLayout_tl_textSelectColor, Color.parseColor("#ffffff"));
mTextUnselectColor = ta.getColor(R.styleable.SegmentTabLayout_tl_textUnselectColor, mIndicatorColor);
mTextBold = ta.getInt(R.styleable.SegmentTabLayout_tl_textBold, TEXT_BOLD_NONE);
mTextAllCaps = ta.getBoolean(R.styleable.SegmentTabLayout_tl_textAllCaps, false);
mTabSpaceEqual = ta.getBoolean(R.styleable.SegmentTabLayout_tl_tab_space_equal, true);
mTabWidth = ta.getDimension(R.styleable.SegmentTabLayout_tl_tab_width, dp2px(-1));
mTabPadding = ta.getDimension(R.styleable.SegmentTabLayout_tl_tab_padding, mTabSpaceEqual || mTabWidth > 0 ? dp2px(0) : dp2px(10));
mBarColor = ta.getColor(R.styleable.SegmentTabLayout_tl_bar_color, Color.TRANSPARENT);
mBarStrokeColor = ta.getColor(R.styleable.SegmentTabLayout_tl_bar_stroke_color, mIndicatorColor);
mBarStrokeWidth = ta.getDimension(R.styleable.SegmentTabLayout_tl_bar_stroke_width, dp2px(1));
ta.recycle();
}
public void setTabData(String[] titles) {
if (titles == null || titles.length == 0) {
throw new IllegalStateException("Titles can not be NULL or EMPTY !");
}
this.mTitles = titles;
notifyDataSetChanged();
}
/** 关联数据支持同时切换fragments */
public void setTabData(String[] titles, FragmentActivity fa, int containerViewId, ArrayList<Fragment> fragments) {
mFragmentChangeManager = new FragmentChangeManager(fa.getSupportFragmentManager(), containerViewId, fragments);
setTabData(titles);
}
/** 更新数据 */
public void notifyDataSetChanged() {
mTabsContainer.removeAllViews();
this.mTabCount = mTitles.length;
View tabView;
for (int i = 0; i < mTabCount; i++) {
tabView = View.inflate(mContext, R.layout.layout_tab_segment, null);
tabView.setTag(i);
addTab(i, tabView);
}
updateTabStyles();
}
/** 创建并添加tab */
private void addTab(final int position, View tabView) {
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
tv_tab_title.setText(mTitles[position]);
tabView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int position = (Integer) v.getTag();
if (mCurrentTab != position) {
setCurrentTab(position);
if (mListener != null) {
mListener.onTabSelect(position);
}
} else {
if (mListener != null) {
mListener.onTabReselect(position);
}
}
}
});
/** 每一个Tab的布局参数 */
LinearLayout.LayoutParams lp_tab = mTabSpaceEqual ?
new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f) :
new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
if (mTabWidth > 0) {
lp_tab = new LinearLayout.LayoutParams((int) mTabWidth, LayoutParams.MATCH_PARENT);
}
mTabsContainer.addView(tabView, position, lp_tab);
}
private void updateTabStyles() {
for (int i = 0; i < mTabCount; i++) {
View tabView = mTabsContainer.getChildAt(i);
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.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
if (mTextAllCaps) {
tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
}
if (mTextBold == TEXT_BOLD_BOTH) {
tv_tab_title.getPaint().setFakeBoldText(true);
} else if (mTextBold == TEXT_BOLD_NONE) {
tv_tab_title.getPaint().setFakeBoldText(false);
}
}
}
private void updateTabSelection(int position) {
for (int i = 0; i < mTabCount; ++i) {
View tabView = mTabsContainer.getChildAt(i);
final boolean isSelect = i == position;
TextView tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
tab_title.setTextColor(isSelect ? mTextSelectColor : mTextUnselectColor);
if (mTextBold == TEXT_BOLD_WHEN_SELECT) {
tab_title.getPaint().setFakeBoldText(isSelect);
}
}
}
private void calcOffset() {
final View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab);
mCurrentP.left = currentTabView.getLeft();
mCurrentP.right = currentTabView.getRight();
final View lastTabView = mTabsContainer.getChildAt(this.mLastTab);
mLastP.left = lastTabView.getLeft();
mLastP.right = lastTabView.getRight();
// Log.d("AAA", "mLastP--->" + mLastP.left + "&" + mLastP.right);
// Log.d("AAA", "mCurrentP--->" + mCurrentP.left + "&" + mCurrentP.right);
if (mLastP.left == mCurrentP.left && mLastP.right == mCurrentP.right) {
invalidate();
} else {
mValueAnimator.setObjectValues(mLastP, mCurrentP);
if (mIndicatorBounceEnable) {
mValueAnimator.setInterpolator(mInterpolator);
}
if (mIndicatorAnimDuration < 0) {
mIndicatorAnimDuration = mIndicatorBounceEnable ? 500 : 250;
}
mValueAnimator.setDuration(mIndicatorAnimDuration);
mValueAnimator.start();
}
}
private void calcIndicatorRect() {
View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab);
float left = currentTabView.getLeft();
float right = currentTabView.getRight();
mIndicatorRect.left = (int) left;
mIndicatorRect.right = (int) right;
if (!mIndicatorAnimEnable) {
if (mCurrentTab == 0) {
/**The corners are ordered top-left, top-right, bottom-right, bottom-left*/
mRadiusArr[0] = mIndicatorCornerRadius;
mRadiusArr[1] = mIndicatorCornerRadius;
mRadiusArr[2] = 0;
mRadiusArr[3] = 0;
mRadiusArr[4] = 0;
mRadiusArr[5] = 0;
mRadiusArr[6] = mIndicatorCornerRadius;
mRadiusArr[7] = mIndicatorCornerRadius;
} else if (mCurrentTab == mTabCount - 1) {
/**The corners are ordered top-left, top-right, bottom-right, bottom-left*/
mRadiusArr[0] = 0;
mRadiusArr[1] = 0;
mRadiusArr[2] = mIndicatorCornerRadius;
mRadiusArr[3] = mIndicatorCornerRadius;
mRadiusArr[4] = mIndicatorCornerRadius;
mRadiusArr[5] = mIndicatorCornerRadius;
mRadiusArr[6] = 0;
mRadiusArr[7] = 0;
} else {
/**The corners are ordered top-left, top-right, bottom-right, bottom-left*/
mRadiusArr[0] = 0;
mRadiusArr[1] = 0;
mRadiusArr[2] = 0;
mRadiusArr[3] = 0;
mRadiusArr[4] = 0;
mRadiusArr[5] = 0;
mRadiusArr[6] = 0;
mRadiusArr[7] = 0;
}
} else {
/**The corners are ordered top-left, top-right, bottom-right, bottom-left*/
mRadiusArr[0] = mIndicatorCornerRadius;
mRadiusArr[1] = mIndicatorCornerRadius;
mRadiusArr[2] = mIndicatorCornerRadius;
mRadiusArr[3] = mIndicatorCornerRadius;
mRadiusArr[4] = mIndicatorCornerRadius;
mRadiusArr[5] = mIndicatorCornerRadius;
mRadiusArr[6] = mIndicatorCornerRadius;
mRadiusArr[7] = mIndicatorCornerRadius;
}
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
IndicatorPoint p = (IndicatorPoint) animation.getAnimatedValue();
mIndicatorRect.left = (int) p.left;
mIndicatorRect.right = (int) p.right;
invalidate();
}
private boolean mIsFirstDraw = true;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode() || mTabCount <= 0) {
return;
}
int height = getHeight();
int paddingLeft = getPaddingLeft();
if (mIndicatorHeight < 0) {
mIndicatorHeight = height - mIndicatorMarginTop - mIndicatorMarginBottom;
}
if (mIndicatorCornerRadius < 0 || mIndicatorCornerRadius > mIndicatorHeight / 2) {
mIndicatorCornerRadius = mIndicatorHeight / 2;
}
//draw rect
mRectDrawable.setColor(mBarColor);
mRectDrawable.setStroke((int) mBarStrokeWidth, mBarStrokeColor);
mRectDrawable.setCornerRadius(mIndicatorCornerRadius);
mRectDrawable.setBounds(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), getHeight() - getPaddingBottom());
mRectDrawable.draw(canvas);
// draw divider
if (!mIndicatorAnimEnable && mDividerWidth > 0) {
mDividerPaint.setStrokeWidth(mDividerWidth);
mDividerPaint.setColor(mDividerColor);
for (int i = 0; i < mTabCount - 1; i++) {
View tab = mTabsContainer.getChildAt(i);
canvas.drawLine(paddingLeft + tab.getRight(), mDividerPadding, paddingLeft + tab.getRight(), height - mDividerPadding, mDividerPaint);
}
}
//draw indicator line
if (mIndicatorAnimEnable) {
if (mIsFirstDraw) {
mIsFirstDraw = false;
calcIndicatorRect();
}
} else {
calcIndicatorRect();
}
mIndicatorDrawable.setColor(mIndicatorColor);
mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left,
(int) mIndicatorMarginTop, (int) (paddingLeft + mIndicatorRect.right - mIndicatorMarginRight),
(int) (mIndicatorMarginTop + mIndicatorHeight));
mIndicatorDrawable.setCornerRadii(mRadiusArr);
mIndicatorDrawable.draw(canvas);
}
//setter and getter
public void setCurrentTab(int currentTab) {
mLastTab = this.mCurrentTab;
this.mCurrentTab = currentTab;
updateTabSelection(currentTab);
if (mFragmentChangeManager != null) {
mFragmentChangeManager.setFragments(currentTab);
}
if (mIndicatorAnimEnable) {
calcOffset();
} else {
invalidate();
}
}
public void setTabPadding(float tabPadding) {
this.mTabPadding = dp2px(tabPadding);
updateTabStyles();
}
public void setTabSpaceEqual(boolean tabSpaceEqual) {
this.mTabSpaceEqual = tabSpaceEqual;
updateTabStyles();
}
public void setTabWidth(float tabWidth) {
this.mTabWidth = dp2px(tabWidth);
updateTabStyles();
}
public void setIndicatorColor(int indicatorColor) {
this.mIndicatorColor = indicatorColor;
invalidate();
}
public void setIndicatorHeight(float indicatorHeight) {
this.mIndicatorHeight = dp2px(indicatorHeight);
invalidate();
}
public void setIndicatorCornerRadius(float indicatorCornerRadius) {
this.mIndicatorCornerRadius = dp2px(indicatorCornerRadius);
invalidate();
}
public void setIndicatorMargin(float indicatorMarginLeft, float indicatorMarginTop,
float indicatorMarginRight, float indicatorMarginBottom) {
this.mIndicatorMarginLeft = dp2px(indicatorMarginLeft);
this.mIndicatorMarginTop = dp2px(indicatorMarginTop);
this.mIndicatorMarginRight = dp2px(indicatorMarginRight);
this.mIndicatorMarginBottom = dp2px(indicatorMarginBottom);
invalidate();
}
public void setIndicatorAnimDuration(long indicatorAnimDuration) {
this.mIndicatorAnimDuration = indicatorAnimDuration;
}
public void setIndicatorAnimEnable(boolean indicatorAnimEnable) {
this.mIndicatorAnimEnable = indicatorAnimEnable;
}
public void setIndicatorBounceEnable(boolean indicatorBounceEnable) {
this.mIndicatorBounceEnable = indicatorBounceEnable;
}
public void setDividerColor(int dividerColor) {
this.mDividerColor = dividerColor;
invalidate();
}
public void setDividerWidth(float dividerWidth) {
this.mDividerWidth = dp2px(dividerWidth);
invalidate();
}
public void setDividerPadding(float dividerPadding) {
this.mDividerPadding = dp2px(dividerPadding);
invalidate();
}
public void setTextsize(float textsize) {
this.mTextsize = sp2px(textsize);
updateTabStyles();
}
public void setTextSelectColor(int textSelectColor) {
this.mTextSelectColor = textSelectColor;
updateTabStyles();
}
public void setTextUnselectColor(int textUnselectColor) {
this.mTextUnselectColor = textUnselectColor;
updateTabStyles();
}
public void setTextBold(int textBold) {
this.mTextBold = textBold;
updateTabStyles();
}
public void setTextAllCaps(boolean textAllCaps) {
this.mTextAllCaps = textAllCaps;
updateTabStyles();
}
public int getTabCount() {
return mTabCount;
}
public int getCurrentTab() {
return mCurrentTab;
}
public float getTabPadding() {
return mTabPadding;
}
public boolean isTabSpaceEqual() {
return mTabSpaceEqual;
}
public float getTabWidth() {
return mTabWidth;
}
public int getIndicatorColor() {
return mIndicatorColor;
}
public float getIndicatorHeight() {
return mIndicatorHeight;
}
public float getIndicatorCornerRadius() {
return mIndicatorCornerRadius;
}
public float getIndicatorMarginLeft() {
return mIndicatorMarginLeft;
}
public float getIndicatorMarginTop() {
return mIndicatorMarginTop;
}
public float getIndicatorMarginRight() {
return mIndicatorMarginRight;
}
public float getIndicatorMarginBottom() {
return mIndicatorMarginBottom;
}
public long getIndicatorAnimDuration() {
return mIndicatorAnimDuration;
}
public boolean isIndicatorAnimEnable() {
return mIndicatorAnimEnable;
}
public boolean isIndicatorBounceEnable() {
return mIndicatorBounceEnable;
}
public int getDividerColor() {
return mDividerColor;
}
public float getDividerWidth() {
return mDividerWidth;
}
public float getDividerPadding() {
return mDividerPadding;
}
public float getTextsize() {
return mTextsize;
}
public int getTextSelectColor() {
return mTextSelectColor;
}
public int getTextUnselectColor() {
return mTextUnselectColor;
}
public int getTextBold() {
return mTextBold;
}
public boolean isTextAllCaps() {
return mTextAllCaps;
}
public TextView getTitleView(int tab) {
View tabView = mTabsContainer.getChildAt(tab);
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
return tv_tab_title;
}
//setter and getter
// show MsgTipView
private Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private SparseArray<Boolean> mInitSetMap = new SparseArray<>();
/**
* 显示未读消息
*
* @param position 显示tab位置
* @param num num小于等于0显示红点,num大于0显示数字
*/
public void showMsg(int position, int num) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
if (tipView != null) {
UnreadMsgUtils.show(tipView, num);
if (mInitSetMap.get(position) != null && mInitSetMap.get(position)) {
return;
}
setMsgMargin(position, 2, 2);
mInitSetMap.put(position, true);
}
}
/**
* 显示未读红点
*
* @param position 显示tab位置
*/
public void showDot(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
showMsg(position, 0);
}
public void hideMsg(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
if (tipView != null) {
tipView.setVisibility(View.GONE);
}
}
/**
* 设置提示红点偏移,注意
* 1.控件为固定高度:参照点为tab内容的右上角
* 2.控件高度不固定(WRAP_CONTENT):参照点为tab内容的右上角,此时高度已是红点的最高显示范围,所以这时bottomPadding其实就是topPadding
*/
public void setMsgMargin(int position, float leftPadding, float bottomPadding) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
if (tipView != null) {
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
mTextPaint.setTextSize(mTextsize);
float textWidth = mTextPaint.measureText(tv_tab_title.getText().toString());
float textHeight = mTextPaint.descent() - mTextPaint.ascent();
MarginLayoutParams lp = (MarginLayoutParams) tipView.getLayoutParams();
lp.leftMargin = dp2px(leftPadding);
lp.topMargin = mHeight > 0 ? (int) (mHeight - textHeight) / 2 - dp2px(bottomPadding) : dp2px(bottomPadding);
tipView.setLayoutParams(lp);
}
}
/** 当前类只提供了少许设置未读消息属性的方法,可以通过该方法获取MsgView对象从而各种设置 */
public MsgView getMsgView(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
return tipView;
}
private OnTabSelectListener mListener;
public void setOnTabSelectListener(OnTabSelectListener listener) {
this.mListener = listener;
}
@Override
protected Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putParcelable("instanceState", super.onSaveInstanceState());
bundle.putInt("mCurrentTab", mCurrentTab);
return bundle;
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
mCurrentTab = bundle.getInt("mCurrentTab");
state = bundle.getParcelable("instanceState");
if (mCurrentTab != 0 && mTabsContainer.getChildCount() > 0) {
updateTabSelection(mCurrentTab);
}
}
super.onRestoreInstanceState(state);
}
class IndicatorPoint {
public float left;
public float right;
}
private IndicatorPoint mCurrentP = new IndicatorPoint();
private IndicatorPoint mLastP = new IndicatorPoint();
class PointEvaluator implements TypeEvaluator<IndicatorPoint> {
@Override
public IndicatorPoint evaluate(float fraction, IndicatorPoint startValue, IndicatorPoint endValue) {
float left = startValue.left + fraction * (endValue.left - startValue.left);
float right = startValue.right + fraction * (endValue.right - startValue.right);
IndicatorPoint point = new IndicatorPoint();
point.left = left;
point.right = right;
return point;
}
}
protected int dp2px(float dp) {
final float scale = mContext.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
protected int sp2px(float sp) {
final float scale = this.mContext.getResources().getDisplayMetrics().scaledDensity;
return (int) (sp * scale + 0.5f);
}
}
================================================
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java
================================================
package com.flyco.tablayout;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.flyco.tablayout.utils.UnreadMsgUtils;
import com.flyco.tablayout.widget.MsgView;
import java.util.ArrayList;
import java.util.Collections;
/** 滑动TabLayout,对于ViewPager的依赖性强 */
public class SlidingTabLayout extends HorizontalScrollView implements ViewPager.OnPageChangeListener {
private Context mContext;
private ViewPager mViewPager;
private ArrayList<String> mTitles;
private LinearLayout mTabsContainer;
private int mCurrentTab;
private float mCurrentPositionOffset;
private int mTabCount;
/** 用于绘制显示器 */
private Rect mIndicatorRect = new Rect();
/** 用于实现滚动居中 */
private Rect mTabRect = new Rect();
private GradientDrawable mIndicatorDrawable = new GradientDrawable();
private Paint mRectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Paint mDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Paint mTrianglePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Path mTrianglePath = new Path();
private static final int STYLE_NORMAL = 0;
private static final int STYLE_TRIANGLE = 1;
private static final int STYLE_BLOCK = 2;
private int mIndicatorStyle = STYLE_NORMAL;
private float mTabPadding;
private boolean mTabSpaceEqual;
private float mTabWidth;
/** indicator */
private int mIndicatorColor;
private float mIndicatorHeight;
private float mIndicatorWidth;
private float mIndicatorCornerRadius;
private float mIndicatorMarginLeft;
private float mIndicatorMarginTop;
private float mIndicatorMarginRight;
private float mIndicatorMarginBottom;
private int mIndicatorGravity;
private boolean mIndicatorWidthEqualTitle;
/** underline */
private int mUnderlineColor;
private float mUnderlineHeight;
private int mUnderlineGravity;
/** divider */
private int mDividerColor;
private float mDividerWidth;
private float mDividerPadding;
/** title */
private static final int TEXT_BOLD_NONE = 0;
private static final int TEXT_BOLD_WHEN_SELECT = 1;
private static final int TEXT_BOLD_BOTH = 2;
private float mTextsize;
private int mTextSelectColor;
private int mTextUnselectColor;
private int mTextBold;
private boolean mTextAllCaps;
private int mLastScrollX;
private int mHeight;
private boolean mSnapOnTabClick;
public SlidingTabLayout(Context context) {
this(context, null, 0);
}
public SlidingTabLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setFillViewport(true);//设置滚动视图是否可以伸缩其内容以填充视口
setWillNotDraw(false);//重写onDraw方法,需要调用这个方法来清除flag
setClipChildren(false);
setClipToPadding(false);
this.mContext = context;
mTabsContainer = new LinearLayout(context);
addView(mTabsContainer);
obtainAttributes(context, attrs);
//get layout_height
String height = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_height");
if (height.equals(ViewGroup.LayoutParams.MATCH_PARENT + "")) {
} else if (height.equals(ViewGroup.LayoutParams.WRAP_CONTENT + "")) {
} else {
int[] systemAttrs = {android.R.attr.layout_height};
TypedArray a = context.obtainStyledAttributes(attrs, systemAttrs);
mHeight = a.getDimensionPixelSize(0, ViewGroup.LayoutParams.WRAP_CONTENT);
a.recycle();
}
}
private void obtainAttributes(Context context, AttributeSet attrs) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout);
mIndicatorStyle = ta.getInt(R.styleable.SlidingTabLayout_tl_indicator_style, STYLE_NORMAL);
mIndicatorColor = ta.getColor(R.styleable.SlidingTabLayout_tl_indicator_color, Color.parseColor(mIndicatorStyle == STYLE_BLOCK ? "#4B6A87" : "#ffffff"));
mIndicatorHeight = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_height,
dp2px(mIndicatorStyle == STYLE_TRIANGLE ? 4 : (mIndicatorStyle == STYLE_BLOCK ? -1 : 2)));
mIndicatorWidth = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_width, dp2px(mIndicatorStyle == STYLE_TRIANGLE ? 10 : -1));
mIndicatorCornerRadius = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_corner_radius, dp2px(mIndicatorStyle == STYLE_BLOCK ? -1 : 0));
mIndicatorMarginLeft = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_left, dp2px(0));
mIndicatorMarginTop = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_top, dp2px(mIndicatorStyle == STYLE_BLOCK ? 7 : 0));
mIndicatorMarginRight = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_right, dp2px(0));
mIndicatorMarginBottom = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_bottom, dp2px(mIndicatorStyle == STYLE_BLOCK ? 7 : 0));
mIndicatorGravity = ta.getInt(R.styleable.SlidingTabLayout_tl_indicator_gravity, Gravity.BOTTOM);
mIndicatorWidthEqualTitle = ta.getBoolean(R.styleable.SlidingTabLayout_tl_indicator_width_equal_title, false);
mUnderlineColor = ta.getColor(R.styleable.SlidingTabLayout_tl_underline_color, Color.parseColor("#ffffff"));
mUnderlineHeight = ta.getDimension(R.styleable.SlidingTabLayout_tl_underline_height, dp2px(0));
mUnderlineGravity = ta.getInt(R.styleable.SlidingTabLayout_tl_underline_gravity, Gravity.BOTTOM);
mDividerColor = ta.getColor(R.styleable.SlidingTabLayout_tl_divider_color, Color.parseColor("#ffffff"));
mDividerWidth = ta.getDimension(R.styleable.SlidingTabLayout_tl_divider_width, dp2px(0));
mDividerPadding = ta.getDimension(R.styleable.SlidingTabLayout_tl_divider_padding, dp2px(12));
mTextsize = ta.getDimension(R.styleable.SlidingTabLayout_tl_textsize, 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);
mTextAllCaps = ta.getBoolean(R.styleable.SlidingTabLayout_tl_textAllCaps, false);
mTabSpaceEqual = ta.getBoolean(R.styleable.SlidingTabLayout_tl_tab_space_equal, false);
mTabWidth = ta.getDimension(R.styleable.SlidingTabLayout_tl_tab_width, dp2px(-1));
mTabPadding = ta.getDimension(R.styleable.SlidingTabLayout_tl_tab_padding, mTabSpaceEqual || mTabWidth > 0 ? dp2px(0) : dp2px(20));
ta.recycle();
}
/** 关联ViewPager */
public void setViewPager(ViewPager vp) {
if (vp == null || vp.getAdapter() == null) {
throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !");
}
this.mViewPager = vp;
this.mViewPager.removeOnPageChangeListener(this);
this.mViewPager.addOnPageChangeListener(this);
notifyDataSetChanged();
}
/** 关联ViewPager,用于不想在ViewPager适配器中设置titles数据的情况 */
public void setViewPager(ViewPager vp, String[] titles) {
if (vp == null || vp.getAdapter() == null) {
throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !");
}
if (titles == null || titles.length == 0) {
throw new IllegalStateException("Titles can not be EMPTY !");
}
if (titles.length != vp.getAdapter().getCount()) {
throw new IllegalStateException("Titles length must be the same as the page count !");
}
this.mViewPager = vp;
mTitles = new ArrayList<>();
Collections.addAll(mTitles, titles);
this.mViewPager.removeOnPageChangeListener(this);
this.mViewPager.addOnPageChangeListener(this);
notifyDataSetChanged();
}
/** 关联ViewPager,用于连适配器都不想自己实例化的情况 */
public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList<Fragment> fragments) {
if (vp == null) {
throw new IllegalStateException("ViewPager can not be NULL !");
}
if (titles == null || titles.length == 0) {
throw new IllegalStateException("Titles can not be EMPTY !");
}
this.mViewPager = vp;
this.mViewPager.setAdapter(new InnerPagerAdapter(fa.getSupportFragmentManager(), fragments, titles));
this.mViewPager.removeOnPageChangeListener(this);
this.mViewPager.addOnPageChangeListener(this);
notifyDataSetChanged();
}
/** 更新数据 */
public void notifyDataSetChanged() {
mTabsContainer.removeAllViews();
this.mTabCount = mTitles == null ? mViewPager.getAdapter().getCount() : mTitles.size();
View tabView;
for (int i = 0; i < mTabCount; i++) {
tabView = View.inflate(mContext, R.layout.layout_tab, null);
CharSequence pageTitle = mTitles == null ? mViewPager.getAdapter().getPageTitle(i) : mTitles.get(i);
addTab(i, pageTitle.toString(), tabView);
}
updateTabStyles();
}
public void addNewTab(String title) {
View tabView = View.inflate(mContext, R.layout.layout_tab, null);
if (mTitles != null) {
mTitles.add(title);
}
CharSequence pageTitle = mTitles == null ? mViewPager.getAdapter().getPageTitle(mTabCount) : mTitles.get(mTabCount);
addTab(mTabCount, pageTitle.toString(), tabView);
this.mTabCount = mTitles == null ? mViewPager.getAdapter().getCount() : mTitles.size();
updateTabStyles();
}
/** 创建并添加tab */
private void addTab(final int position, String title, View tabView) {
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
if (tv_tab_title != null) {
if (title != null) tv_tab_title.setText(title);
}
tabView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int position = mTabsContainer.indexOfChild(v);
if (position != -1) {
if (mViewPager.getCurrentItem() != position) {
if (mSnapOnTabClick) {
mViewPager.setCurrentItem(position, false);
} else {
mViewPager.setCurrentItem(position);
}
if (mListener != null) {
mListener.onTabSelect(position);
}
} else {
if (mListener != null) {
mListener.onTabReselect(position);
}
}
}
}
});
/** 每一个Tab的布局参数 */
LinearLayout.LayoutParams lp_tab = mTabSpaceEqual ?
new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f) :
new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
if (mTabWidth > 0) {
lp_tab = new LinearLayout.LayoutParams((int) mTabWidth, LayoutParams.MATCH_PARENT);
}
mTabsContainer.addView(tabView, position, lp_tab);
}
private void updateTabStyles() {
for (int i = 0; i < mTabCount; i++) {
View v = mTabsContainer.getChildAt(i);
// v.setPadding((int) mTabPadding, v.getPaddingTop(), (int) mTabPadding, v.getPaddingBottom());
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.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
if (mTextAllCaps) {
tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
}
if (mTextBold == TEXT_BOLD_BOTH) {
tv_tab_title.getPaint().setFakeBoldText(true);
} else if (mTextBold == TEXT_BOLD_NONE) {
tv_tab_title.getPaint().setFakeBoldText(false);
}
}
}
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
/**
* position:当前View的位置
* mCurrentPositionOffset:当前View的偏移量比例.[0,1)
*/
this.mCurrentTab = position;
this.mCurrentPositionOffset = positionOffset;
scrollToCurrentTab();
invalidate();
}
@Override
public void onPageSelected(int position) {
updateTabSelection(position);
}
@Override
public void onPageScrollStateChanged(int state) {
}
/** HorizontalScrollView滚到当前tab,并且居中显示 */
private void scrollToCurrentTab() {
if (mTabCount <= 0) {
return;
}
int offset = (int) (mCurrentPositionOffset * mTabsContainer.getChildAt(mCurrentTab).getWidth());
/**当前Tab的left+当前Tab的Width乘以positionOffset*/
int newScrollX = mTabsContainer.getChildAt(mCurrentTab).getLeft() + offset;
if (mCurrentTab > 0 || offset > 0) {
/**HorizontalScrollView移动到当前tab,并居中*/
newScrollX -= getWidth() / 2 - getPaddingLeft();
calcIndicatorRect();
newScrollX += ((mTabRect.right - mTabRect.left) / 2);
}
if (newScrollX != mLastScrollX) {
mLastScrollX = newScrollX;
/** scrollTo(int x,int y):x,y代表的不是坐标点,而是偏移量
* x:表示离起始位置的x水平方向的偏移量
* y:表示离起始位置的y垂直方向的偏移量
*/
scrollTo(newScrollX, 0);
}
}
private void updateTabSelection(int position) {
for (int i = 0; i < mTabCount; ++i) {
View tabView = mTabsContainer.getChildAt(i);
final boolean isSelect = i == position;
TextView tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
if (tab_title != null) {
tab_title.setTextColor(isSelect ? mTextSelectColor : mTextUnselectColor);
if (mTextBold == TEXT_BOLD_WHEN_SELECT) {
tab_title.getPaint().setFakeBoldText(isSelect);
}
}
}
}
private float margin;
private void calcIndicatorRect() {
View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab);
float left = currentTabView.getLeft();
float right = currentTabView.getRight();
//for mIndicatorWidthEqualTitle
if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) {
TextView tab_title = (TextView) currentTabView.findViewById(R.id.tv_tab_title);
mTextPaint.setTextSize(mTextsize);
float textWidth = mTextPaint.measureText(tab_title.getText().toString());
margin = (right - left - textWidth) / 2;
}
if (this.mCurrentTab < mTabCount - 1) {
View nextTabView = mTabsContainer.getChildAt(this.mCurrentTab + 1);
float nextTabLeft = nextTabView.getLeft();
float nextTabRight = nextTabView.getRight();
left = left + mCurrentPositionOffset * (nextTabLeft - left);
right = right + mCurrentPositionOffset * (nextTabRight - right);
//for mIndicatorWidthEqualTitle
if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) {
TextView next_tab_title = (TextView) nextTabView.findViewById(R.id.tv_tab_title);
mTextPaint.setTextSize(mTextsize);
float nextTextWidth = mTextPaint.measureText(next_tab_title.getText().toString());
float nextMargin = (nextTabRight - nextTabLeft - nextTextWidth) / 2;
margin = margin + mCurrentPositionOffset * (nextMargin - margin);
}
}
mIndicatorRect.left = (int) left;
mIndicatorRect.right = (int) right;
//for mIndicatorWidthEqualTitle
if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) {
mIndicatorRect.left = (int) (left + margin - 1);
mIndicatorRect.right = (int) (right - margin - 1);
}
mTabRect.left = (int) left;
mTabRect.right = (int) right;
if (mIndicatorWidth < 0) { //indicatorWidth小于0时,原jpardogo's PagerSlidingTabStrip
} else {//indicatorWidth大于0时,圆角矩形以及三角形
float indicatorLeft = currentTabView.getLeft() + (currentTabView.getWidth() - mIndicatorWidth) / 2;
if (this.mCurrentTab < mTabCount - 1) {
View nextTab = mTabsContainer.getChildAt(this.mCurrentTab + 1);
indicatorLeft = indicatorLeft + mCurrentPositionOffset * (currentTabView.getWidth() / 2 + nextTab.getWidth() / 2);
}
mIndicatorRect.left = (int) indicatorLeft;
mIndicatorRect.right = (int) (mIndicatorRect.left + mIndicatorWidth);
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode() || mTabCount <= 0) {
return;
}
int height = getHeight();
int paddingLeft = getPaddingLeft();
// draw divider
if (mDividerWidth > 0) {
mDividerPaint.setStrokeWidth(mDividerWidth);
mDividerPaint.setColor(mDividerColor);
for (int i = 0; i < mTabCount - 1; i++) {
View tab = mTabsContainer.getChildAt(i);
canvas.drawLine(paddingLeft + tab.getRight(), mDividerPadding, paddingLeft + tab.getRight(), height - mDividerPadding, mDividerPaint);
}
}
// draw underline
if (mUnderlineHeight > 0) {
mRectPaint.setColor(mUnderlineColor);
if (mUnderlineGravity == Gravity.BOTTOM) {
canvas.drawRect(paddingLeft, height - mUnderlineHeight, mTabsContainer.getWidth() + paddingLeft, height, mRectPaint);
} else {
canvas.drawRect(paddingLeft, 0, mTabsContainer.getWidth() + paddingLeft, mUnderlineHeight, mRectPaint);
}
}
//draw indicator line
calcIndicatorRect();
if (mIndicatorStyle == STYLE_TRIANGLE) {
if (mIndicatorHeight > 0) {
mTrianglePaint.setColor(mIndicatorColor);
mTrianglePath.reset();
mTrianglePath.moveTo(paddingLeft + mIndicatorRect.left, height);
mTrianglePath.lineTo(paddingLeft + mIndicatorRect.left / 2 + mIndicatorRect.right / 2, height - mIndicatorHeight);
mTrianglePath.lineTo(paddingLeft + mIndicatorRect.right, height);
mTrianglePath.close();
canvas.drawPath(mTrianglePath, mTrianglePaint);
}
} else if (mIndicatorStyle == STYLE_BLOCK) {
if (mIndicatorHeight < 0) {
mIndicatorHeight = height - mIndicatorMarginTop - mIndicatorMarginBottom;
} else {
}
if (mIndicatorHeight > 0) {
if (mIndicatorCornerRadius < 0 || mIndicatorCornerRadius > mIndicatorHeight / 2) {
mIndicatorCornerRadius = mIndicatorHeight / 2;
}
mIndicatorDrawable.setColor(mIndicatorColor);
mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left,
(int) mIndicatorMarginTop, (int) (paddingLeft + mIndicatorRect.right - mIndicatorMarginRight),
(int) (mIndicatorMarginTop + mIndicatorHeight));
mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius);
mIndicatorDrawable.draw(canvas);
}
} else {
/* mRectPaint.setColor(mIndicatorColor);
calcIndicatorRect();
canvas.drawRect(getPaddingLeft() + mIndicatorRect.left, getHeight() - mIndicatorHeight,
mIndicatorRect.right + getPaddingLeft(), getHeight(), mRectPaint);*/
if (mIndicatorHeight > 0) {
mIndicatorDrawable.setColor(mIndicatorColor);
if (mIndicatorGravity == Gravity.BOTTOM) {
mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left,
height - (int) mIndicatorHeight - (int) mIndicatorMarginBottom,
paddingLeft + mIndicatorRect.right - (int) mIndicatorMarginRight,
height - (int) mIndicatorMarginBottom);
} else {
mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left,
(int) mIndicatorMarginTop,
paddingLeft + mIndicatorRect.right - (int) mIndicatorMarginRight,
(int) mIndicatorHeight + (int) mIndicatorMarginTop);
}
mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius);
mIndicatorDrawable.draw(canvas);
}
}
}
//setter and getter
public void setCurrentTab(int currentTab) {
this.mCurrentTab = currentTab;
mViewPager.setCurrentItem(currentTab);
}
public void setCurrentTab(int currentTab, boolean smoothScroll) {
this.mCurrentTab = currentTab;
mViewPager.setCurrentItem(currentTab, smoothScroll);
}
public void setIndicatorStyle(int indicatorStyle) {
this.mIndicatorStyle = indicatorStyle;
invalidate();
}
public void setTabPadding(float tabPadding) {
this.mTabPadding = dp2px(tabPadding);
updateTabStyles();
}
public void setTabSpaceEqual(boolean tabSpaceEqual) {
this.mTabSpaceEqual = tabSpaceEqual;
updateTabStyles();
}
public void setTabWidth(float tabWidth) {
this.mTabWidth = dp2px(tabWidth);
updateTabStyles();
}
public void setIndicatorColor(int indicatorColor) {
this.mIndicatorColor = indicatorColor;
invalidate();
}
public void setIndicatorHeight(float indicatorHeight) {
this.mIndicatorHeight = dp2px(indicatorHeight);
invalidate();
}
public void setIndicatorWidth(float indicatorWidth) {
this.mIndicatorWidth = dp2px(indicatorWidth);
invalidate();
}
public void setIndicatorCornerRadius(float indicatorCornerRadius) {
this.mIndicatorCornerRadius = dp2px(indicatorCornerRadius);
invalidate();
}
public void setIndicatorGravity(int indicatorGravity) {
this.mIndicatorGravity = indicatorGravity;
invalidate();
}
public void setIndicatorMargin(float indicatorMarginLeft, float indicatorMarginTop,
float indicatorMarginRight, float indicatorMarginBottom) {
this.mIndicatorMarginLeft = dp2px(indicatorMarginLeft);
this.mIndicatorMarginTop = dp2px(indicatorMarginTop);
this.mIndicatorMarginRight = dp2px(indicatorMarginRight);
this.mIndicatorMarginBottom = dp2px(indicatorMarginBottom);
invalidate();
}
public void setIndicatorWidthEqualTitle(boolean indicatorWidthEqualTitle) {
this.mIndicatorWidthEqualTitle = indicatorWidthEqualTitle;
invalidate();
}
public void setUnderlineColor(int underlineColor) {
this.mUnderlineColor = underlineColor;
invalidate();
}
public void setUnderlineHeight(float underlineHeight) {
this.mUnderlineHeight = dp2px(underlineHeight);
invalidate();
}
public void setUnderlineGravity(int underlineGravity) {
this.mUnderlineGravity = underlineGravity;
invalidate();
}
public void setDividerColor(int dividerColor) {
this.mDividerColor = dividerColor;
invalidate();
}
public void setDividerWidth(float dividerWidth) {
this.mDividerWidth = dp2px(dividerWidth);
invalidate();
}
public void setDividerPadding(float dividerPadding) {
this.mDividerPadding = dp2px(dividerPadding);
invalidate();
}
public void setTextsize(float textsize) {
this.mTextsize = sp2px(textsize);
updateTabStyles();
}
public void setTextSelectColor(int textSelectColor) {
this.mTextSelectColor = textSelectColor;
updateTabStyles();
}
public void setTextUnselectColor(int textUnselectColor) {
this.mTextUnselectColor = textUnselectColor;
updateTabStyles();
}
public void setTextBold(int textBold) {
this.mTextBold = textBold;
updateTabStyles();
}
public void setTextAllCaps(boolean textAllCaps) {
this.mTextAllCaps = textAllCaps;
updateTabStyles();
}
public void setSnapOnTabClick(boolean snapOnTabClick) {
mSnapOnTabClick = snapOnTabClick;
}
public int getTabCount() {
return mTabCount;
}
public int getCurrentTab() {
return mCurrentTab;
}
public int getIndicatorStyle() {
return mIndicatorStyle;
}
public float getTabPadding() {
return mTabPadding;
}
public boolean isTabSpaceEqual() {
return mTabSpaceEqual;
}
public float getTabWidth() {
return mTabWidth;
}
public int getIndicatorColor() {
return mIndicatorColor;
}
public float getIndicatorHeight() {
return mIndicatorHeight;
}
public float getIndicatorWidth() {
return mIndicatorWidth;
}
public float getIndicatorCornerRadius() {
return mIndicatorCornerRadius;
}
public float getIndicatorMarginLeft() {
return mIndicatorMarginLeft;
}
public float getIndicatorMarginTop() {
return mIndicatorMarginTop;
}
public float getIndicatorMarginRight() {
return mIndicatorMarginRight;
}
public float getIndicatorMarginBottom() {
return mIndicatorMarginBottom;
}
public int getUnderlineColor() {
return mUnderlineColor;
}
public float getUnderlineHeight() {
return mUnderlineHeight;
}
public int getDividerColor() {
return mDividerColor;
}
public float getDividerWidth() {
return mDividerWidth;
}
public float getDividerPadding() {
return mDividerPadding;
}
public float getTextsize() {
return mTextsize;
}
public int getTextSelectColor() {
return mTextSelectColor;
}
public int getTextUnselectColor() {
return mTextUnselectColor;
}
public int getTextBold() {
return mTextBold;
}
public boolean isTextAllCaps() {
return mTextAllCaps;
}
public TextView getTitleView(int tab) {
View tabView = mTabsContainer.getChildAt(tab);
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
return tv_tab_title;
}
//setter and getter
// show MsgTipView
private Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private SparseArray<Boolean> mInitSetMap = new SparseArray<>();
/**
* 显示未读消息
*
* @param position 显示tab位置
* @param num num小于等于0显示红点,num大于0显示数字
*/
public void showMsg(int position, int num) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
if (tipView != null) {
UnreadMsgUtils.show(tipView, num);
if (mInitSetMap.get(position) != null && mInitSetMap.get(position)) {
return;
}
setMsgMargin(position, 4, 2);
mInitSetMap.put(position, true);
}
}
/**
* 显示未读红点
*
* @param position 显示tab位置
*/
public void showDot(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
showMsg(position, 0);
}
/** 隐藏未读消息 */
public void hideMsg(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
if (tipView != null) {
tipView.setVisibility(View.GONE);
}
}
/** 设置未读消息偏移,原点为文字的右上角.当控件高度固定,消息提示位置易控制,显示效果佳 */
public void setMsgMargin(int position, float leftPadding, float bottomPadding) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
if (tipView != null) {
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
mTextPaint.setTextSize(mTextsize);
float textWidth = mTextPaint.measureText(tv_tab_title.getText().toString());
float textHeight = mTextPaint.descent() - mTextPaint.ascent();
MarginLayoutParams lp = (MarginLayoutParams) tipView.getLayoutParams();
lp.leftMargin = mTabWidth >= 0 ? (int) (mTabWidth / 2 + textWidth / 2 + dp2px(leftPadding)) : (int) (mTabPadding + textWidth + dp2px(leftPadding));
lp.topMargin = mHeight > 0 ? (int) (mHeight - textHeight) / 2 - dp2px(bottomPadding) : 0;
tipView.setLayoutParams(lp);
}
}
/** 当前类只提供了少许设置未读消息属性的方法,可以通过该方法获取MsgView对象从而各种设置 */
public MsgView getMsgView(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
}
View tabView = mTabsContainer.getChildAt(position);
MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip);
return tipView;
}
private OnTabSelectListener mListener;
public void setOnTabSelectListener(OnTabSelectListener listener) {
this.mListener = listener;
}
class InnerPagerAdapter extends FragmentPagerAdapter {
private ArrayList<Fragment> fragments = new ArrayList<>();
private String[] titles;
public InnerPagerAdapter(FragmentManager fm, ArrayList<Fragment> fragments, String[] titles) {
super(fm);
this.fragments = fragments;
this.titles = titles;
}
@Override
public int getCount() {
return fragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return titles[position];
}
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// 覆写destroyItem并且空实现,这样每个Fragment中的视图就不会被销毁
// super.destroyItem(container, position, object);
}
@Override
public int getItemPosition(Object object) {
return PagerAdapter.POSITION_NONE;
}
}
@Override
protected Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putParcelable("instanceState", super.onSaveInstanceState());
bundle.putInt("mCurrentTab", mCurrentTab);
return bundle;
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
mCurrentTab = bundle.getInt("mCurrentTab");
state = bundle.getParcelable("instanceState");
if (mCurrentTab != 0 && mTabsContainer.getChildCount() > 0) {
updateTabSelection(mCurrentTab);
scrollToCurrentTab();
}
}
super.onRestoreInstanceState(state);
}
protected int dp2px(float dp) {
final float scale = mContext.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
protected int sp2px(float sp) {
final float scale = this.mContext.getResources().getDisplayMetrics().scaledDensity;
return (int) (sp * scale + 0.5f);
}
}
================================================
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/listener/CustomTabEntity.java
================================================
package com.flyco.tablayout.listener;
import androidx.annotation.DrawableRes;
public interface CustomTabEntity {
String getTabTitle();
@DrawableRes
int getTabSelectedIcon();
@DrawableRes
int getTabUnselectedIcon();
}
================================================
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/listener/OnTabSelectListener.java
================================================
package com.flyco.tablayout.listener;
public interface OnTabSelectListener {
void onTabSelect(int position);
void onTabReselect(int position);
}
================================================
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/utils/FragmentChangeManager.java
================================================
package com.flyco.tablayout.utils;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import java.util.ArrayList;
public class FragmentChangeManager {
private FragmentManager mFragmentManager;
private int mContainerViewId;
/** Fragment切换数组 */
private ArrayList<Fragment> mFragments;
/** 当前选中的Tab */
private int mCurrentTab;
public FragmentChangeManager(FragmentManager fm, int containerViewId, ArrayList<Fragment> fragments) {
this.mFragmentManager = fm;
this.mContainerViewId = containerViewId;
this.mFragments = fragments;
initFragments();
}
/** 初始化fragments */
private void initFragments() {
for (Fragment fragment : mFragments) {
mFragmentManager.beginTransaction().add(mContainerViewId, fragment).hide(fragment).commit();
}
setFragments(0);
}
/** 界面切换控制 */
public void setFragments(int index) {
for (int i = 0; i < mFragments.size(); i++) {
FragmentTransaction ft = mFragmentManager.beginTransaction();
Fragment fragment = mFragments.get(i);
if (i == index) {
ft.show(fragment);
} else {
ft.hide(fragment);
}
ft.commit();
}
mCurrentTab = index;
}
public int getCurrentTab() {
return mCurrentTab;
}
public Fragment getCurrentFragment() {
return mFragments.get(mCurrentTab);
}
}
================================================
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/utils/UnreadMsgUtils.java
================================================
package com.flyco.tablayout.utils;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.RelativeLayout;
import com.flyco.tablayout.widget.MsgView;
/**
* 未读消息提示View,显示小红点或者带有数字的红点:
* 数字一位,圆
* 数字两位,圆角矩形,圆角是高度的一半
* 数字超过两位,显示99+
*/
public class UnreadMsgUtils {
public static void show(MsgView msgView, int num) {
if (msgView == null) {
return;
}
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) msgView.getLayoutParams();
DisplayMetrics dm = msgView.getResources().getDisplayMetrics();
msgView.setVisibility(View.VISIBLE);
if (num <= 0) {//圆点,设置默认宽高
msgView.setStrokeWidth(0);
msgView.setText("");
lp.width = (int) (5 * dm.density);
lp.height = (int) (5 * dm.density);
msgView.setLayoutParams(lp);
} else {
lp.height = (int) (18 * dm.density);
if (num > 0 && num < 10) {//圆
lp.width = (int) (18 * dm.density);
msgView.setText(num + "");
} else if (num > 9 && num < 100) {//圆角矩形,圆角是高度的一半,设置默认padding
lp.width = RelativeLayout.LayoutParams.WRAP_CONTENT;
msgView.setPadding((int) (6 * dm.density), 0, (int) (6 * dm.density), 0);
msgView.setText(num + "");
} else {//数字超过两位,显示99+
lp.width = RelativeLayout.LayoutParams.WRAP_CONTENT;
msgView.setPadding((int) (6 * dm.density), 0, (int) (6 * dm.density), 0);
msgView.setText("99+");
}
msgView.setLayoutParams(lp);
}
}
public static void setSize(MsgView rtv, int size) {
if (rtv == null) {
return;
}
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) rtv.getLayoutParams();
lp.width = size;
lp.height = size;
rtv.setLayoutParams(lp);
}
}
================================================
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/widget/MsgView.java
================================================
package com.flyco.tablayout.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.TextView;
import com.flyco.tablayout.R;
/** 用于需要圆角矩形框背景的TextView的情况,减少直接使用TextView时引入的shape资源文件 */
public class MsgView extends TextView {
private Context context;
private GradientDrawable gd_background = new GradientDrawable();
private int backgroundColor;
private int cornerRadius;
private int strokeWidth;
private int strokeColor;
private boolean isRadiusHalfHeight;
private boolean isWidthHeightEqual;
public MsgView(Context context) {
this(context, null);
}
public MsgView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public MsgView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
obtainAttributes(context, attrs);
}
private void obtainAttributes(Context context, AttributeSet attrs) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MsgView);
backgroundColor = ta.getColor(R.styleable.MsgView_mv_backgroundColor, Color.TRANSPARENT);
cornerRadius = ta.getDimensionPixelSize(R.styleable.MsgView_mv_cornerRadius, 0);
strokeWidth = ta.getDimensionPixelSize(R.styleable.MsgView_mv_strokeWidth, 0);
strokeColor = ta.getColor(R.styleable.MsgView_mv_strokeColor, Color.TRANSPARENT);
isRadiusHalfHeight = ta.getBoolean(R.styleable.MsgView_mv_isRadiusHalfHeight, false);
isWidthHeightEqual = ta.getBoolean(R.styleable.MsgView_mv_isWidthHeightEqual, false);
ta.recycle();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (isWidthHeightEqual() && getWidth() > 0 && getHeight() > 0) {
int max = Math.max(getWidth(), getHeight());
int measureSpec = MeasureSpec.makeMeasureSpec(max, MeasureSpec.EXACTLY);
super.onMeasure(measureSpec, measureSpec);
return;
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (isRadiusHalfHeight()) {
setCornerRadius(getHeight() / 2);
} else {
setBgSelector();
}
}
public void setBackgroundColor(int backgroundColor) {
this.backgroundColor = backgroundColor;
setBgSelector();
}
public void setCornerRadius(int cornerRadius) {
this.cornerRadius = dp2px(cornerRadius);
setBgSelector();
}
public void setStrokeWidth(int strokeWidth) {
this.strokeWidth = dp2px(strokeWidth);
setBgSelector();
}
public void setStrokeColor(int strokeColor) {
this.strokeColor = strokeColor;
setBgSelector();
}
public void setIsRadiusHalfHeight(boolean isRadiusHalfHeight) {
this.isRadiusHalfHeight = isRadiusHalfHeight;
setBgSelector();
}
public void setIsWidthHeightEqual(boolean isWidthHeightEqual) {
this.isWidthHeightEqual = isWidthHeightEqual;
setBgSelector();
}
public int getBackgroundColor() {
return backgroundColor;
}
public int getCornerRadius() {
return cornerRadius;
}
public int getStrokeWidth() {
return strokeWidth;
}
public int getStrokeColor() {
return strokeColor;
}
public boolean isRadiusHalfHeight() {
return isRadiusHalfHeight;
}
public boolean isWidthHeightEqual() {
return isWidthHeightEqual;
}
protected int dp2px(float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
protected int sp2px(float sp) {
final float scale = this.context.getResources().getDisplayMetrics().scaledDensity;
return (int) (sp * scale + 0.5f);
}
private void setDrawable(GradientDrawable gd, int color, int strokeColor) {
gd.setColor(color);
gd.setCornerRadius(cornerRadius);
gd.setStroke(strokeWidth, strokeColor);
}
public void setBgSelector() {
StateListDrawable bg = new StateListDrawable();
setDrawable(gd_background, backgroundColor, strokeColor);
bg.addState(new int[]{-android.R.attr.state_pressed}, gd_background);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {//16
setBackground(bg);
} else {
//noinspection deprecation
setBackgroundDrawable(bg);
}
}
}
================================================
FILE: FlycoTabLayout_Lib/src/main/res/layout/layout_tab.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false">
<TextView
android:id="@+id/tv_tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:singleLine="true"/>
<com.flyco.tablayout.widget.MsgView
android:id="@+id/rtv_msg_tip"
xmlns:mv="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="11.5sp"
android:visibility="gone"
mv:mv_backgroundColor="#FD481F"
mv:mv_isRadiusHalfHeight="true"
mv:mv_strokeColor="#ffffff"
mv:mv_strokeWidth="1dp"/>
</RelativeLayout>
================================================
FILE: FlycoTabLayout_Lib/src/main/res/layout/layout_tab_bottom.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false">
<LinearLayout
android:id="@+id/ll_tap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tv_tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"/>
<ImageView
android:id="@+id/iv_tab_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<com.flyco.tablayout.widget.MsgView
android:id="@+id/rtv_msg_tip"
xmlns:mv="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ll_tap"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="11.5sp"
android:visibility="gone"
mv:mv_backgroundColor="#FD481F"
mv:mv_isRadiusHalfHeight="true"
mv:mv_strokeColor="#ffffff"
mv:mv_strokeWidth="1dp"/>
</RelativeLayout>
================================================
FILE: FlycoTabLayout_Lib/src/main/res/layout/layout_tab_left.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false">
<LinearLayout
android:id="@+id/ll_tap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_tab_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv_tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"/>
</LinearLayout>
<com.flyco.tablayout.widget.MsgView
android:layout_toRightOf="@+id/ll_tap"
android:id="@+id/rtv_msg_tip"
xmlns:mv="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="11.5sp"
android:visibility="gone"
mv:mv_backgroundColor="#FD481F"
mv:mv_isRadiusHalfHeight="true"
mv:mv_strokeColor="#ffffff"
mv:mv_strokeWidth="1dp"/>
</RelativeLayout>
================================================
FILE: FlycoTabLayout_Lib/src/main/res/layout/layout_tab_right.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false">
<LinearLayout
android:id="@+id/ll_tap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"/>
<ImageView
android:id="@+id/iv_tab_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<com.flyco.tablayout.widget.MsgView
android:id="@+id/rtv_msg_tip"
xmlns:mv="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ll_tap"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="11.5sp"
android:visibility="gone"
mv:mv_backgroundColor="#FD481F"
mv:mv_isRadiusHalfHeight="true"
mv:mv_strokeColor="#ffffff"
mv:mv_strokeWidth="1dp"/>
</RelativeLayout>
================================================
FILE: FlycoTabLayout_Lib/src/main/res/layout/layout_tab_segment.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false">
<LinearLayout
android:id="@+id/ll_tap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"/>
</LinearLayout>
<com.flyco.tablayout.widget.MsgView
android:layout_toRightOf="@+id/ll_tap"
android:id="@+id/rtv_msg_tip"
xmlns:mv="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="11.5sp"
android:visibility="gone"
mv:mv_backgroundColor="#FD481F"
mv:mv_isRadiusHalfHeight="true"
mv:mv_strokeColor="#ffffff"
mv:mv_strokeWidth="1dp"/>
</RelativeLayout>
================================================
FILE: FlycoTabLayout_Lib/src/main/res/layout/layout_tab_top.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false">
<LinearLayout
android:id="@+id/ll_tap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_tab_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv_tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"/>
</LinearLayout>
<com.flyco.tablayout.widget.MsgView
android:id="@+id/rtv_msg_tip"
xmlns:mv="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ll_tap"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="11.5sp"
android:visibility="gone"
mv:mv_backgroundColor="#FD481F"
mv:mv_isRadiusHalfHeight="true"
mv:mv_strokeColor="#ffffff"
mv:mv_strokeWidth="1dp"/>
</RelativeLayout>
================================================
FILE: FlycoTabLayout_Lib/src/main/res/values/attrs.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- indicator -->
<!-- 设置显示器颜色 -->
<attr name="tl_indicator_color" format="color"/>
<!-- 设置显示器高度 -->
<attr name="tl_indicator_height" format="dimension"/>
<!-- 设置显示器固定宽度 -->
<attr name="tl_indicator_width" format="dimension"/>
<!-- 设置显示器margin,当indicator_width大于0,无效 -->
<attr name="tl_indicator_margin_left" format="dimension"/>
<attr name="tl_indicator_margin_top" format="dimension"/>
<attr name="tl_indicator_margin_right" format="dimension"/>
<attr name="tl_indicator_margin_bottom" format="dimension"/>
<!-- 设置显示器圆角弧度-->
<attr name="tl_indicator_corner_radius" format="dimension"/>
<!-- 设置显示器上方还是下方,只对圆角矩形有用-->
<attr name="tl_indicator_gravity" format="enum">
<enum name="TOP" value="48"/>
<enum name="BOTTOM" value="80"/>
</attr>
<!-- 设置显示器为常规|三角形|背景色块|-->
<attr name="tl_indicator_style" format="enum">
<enum name="NORMAL" value="0"/>
<enum name="TRIANGLE" value="1"/>
<enum name="BLOCK" value="2"/>
</attr>
<!-- 设置显示器长度与title一样长,只有在STYLE_NORMAL并且indicatorWidth小于零有效-->
<attr name="tl_indicator_width_equal_title" format="boolean"/>
<!-- 设置显示器支持动画-->
<attr name="tl_indicator_anim_enable" format="boolean"/>
<!-- 设置显示器动画时间-->
<attr name="tl_indicator_anim_duration" format="integer"/>
<!-- 设置显示器支持动画回弹效果-->
<attr name="tl_indicator_bounce_enable" format="boolean"/>
<!-- underline -->
<!-- 设置下划线颜色 -->
<attr name="tl_underline_color" format="color"/>
<!-- 设置下划线高度 -->
<attr name="tl_underline_height" format="dimension"/>
<!-- 设置下划线上方还是下方-->
<attr name="tl_underline_gravity" format="enum">
<enum name="TOP" value="48"/>
<enum name="BOTTOM" value="80"/>
</attr>
<!-- divider -->
<!-- 设置分割线颜色 -->
<attr name="tl_divider_color" format="color"/>
<!-- 设置分割线宽度 -->
<attr name="tl_divider_width" format="dimension"/>
<!-- 设置分割线的paddingTop和paddingBottom -->
<attr name="tl_divider_padding" format="dimension"/>
<!-- tab -->
<!-- 设置tab的paddingLeft和paddingRight -->
<attr name="tl_tab_padding" format="dimension"/>
<!-- 设置tab大小等分 -->
<attr name="tl_tab_space_equal" format="boolean"/>
<!-- 设置tab固定大小 -->
<attr name="tl_tab_width" format="dimension"/>
<!-- title -->
<!-- 设置字体大小 -->
<attr name="tl_textsize" format="dimension"/>
<!-- 设置字体选中颜色 -->
<attr name="tl_textSelectColor" format="color"/>
<!-- 设置字体未选中颜色 -->
<attr name="tl_textUnselectColor" format="color"/>
<!-- 设置字体加粗 -->
<attr name="tl_textBold" format="enum">
<enum name="NONE" value="0"/>
<enum name="SELECT" value="1"/>
<enum name="BOTH" value="2"/>
</attr>
<!-- 设置字体全大写 -->
<attr name="tl_textAllCaps" format="boolean"/>
<declare-styleable name="SlidingTabLayout">
<!-- indicator -->
<attr name="tl_indicator_color"/>
<attr name="tl_indicator_height"/>
<attr name="tl_indicator_width"/>
<attr name="tl_indicator_margin_left"/>
<attr name="tl_indicator_margin_top"/>
<attr name="tl_indicator_margin_right"/>
<attr name="tl_indicator_margin_bottom"/>
<attr name="tl_indicator_corner_radius"/>
<attr name="tl_indicator_gravity"/>
<attr name="tl_indicator_style"/>
<attr name="tl_indicator_width_equal_title"/>
<!-- underline -->
<attr name="tl_underline_color"/>
<attr name="tl_underline_height"/>
<attr name="tl_underline_gravity"/>
<!-- divider -->
<attr name="tl_divider_color"/>
<attr name="tl_divider_width"/>
<attr name="tl_divider_padding"/>
<!-- tab -->
<attr name="tl_tab_padding"/>
<attr name="tl_tab_space_equal"/>
<attr name="tl_tab_width"/>
<!-- title -->
<attr name="tl_textsize"/>
<attr name="tl_textSelectColor"/>
<attr name="tl_textUnselectColor"/>
<attr name="tl_textBold"/>
<attr name="tl_textAllCaps"/>
</declare-styleable>
<declare-styleable name="CommonTabLayout">
<!-- indicator -->
<attr name="tl_indicator_color"/>
<attr name="tl_indicator_height"/>
<attr name="tl_indicator_width"/>
<attr name="tl_indicator_margin_left"/>
<attr name="tl_indicator_margin_top"/>
<attr name="tl_indicator_margin_right"/>
<attr name="tl_indicator_margin_bottom"/>
<attr name="tl_indicator_corner_radius"/>
<attr name="tl_indicator_gravity"/>
<attr name="tl_indicator_style"/>
<attr name="tl_indicator_anim_enable"/>
<attr name="tl_indicator_anim_duration"/>
<attr name="tl_indicator_bounce_enable"/>
<!-- underline -->
<attr name="tl_underline_color"/>
<attr name="tl_underline_height"/>
<attr name="tl_underline_gravity"/>
<!-- divider -->
<attr name="tl_divider_color"/>
<attr name="tl_divider_width"/>
<attr name="tl_divider_padding"/>
<!-- tab -->
<attr name="tl_tab_padding"/>
<attr name="tl_tab_space_equal"/>
<attr name="tl_tab_width"/>
<!-- title -->
<attr name="tl_textsize"/>
<attr name="tl_textSelectColor"/>
<attr name="tl_textUnselectColor"/>
<attr name="tl_textBold"/>
<attr name="tl_textAllCaps"/>
<!-- icon -->
<!-- 设置icon宽度 -->
<attr name="tl_iconWidth" format="dimension"/>
<!-- 设置icon高度 -->
<attr name="tl_iconHeight" format="dimension"/>
<!-- 设置icon是否可见 -->
<attr name="tl_iconVisible" format="boolean"/>
<!-- 设置icon显示位置,对应Gravity中常量值 -->
<attr name="tl_iconGravity" format="enum">
<enum name="LEFT" value="3"/>
<enum name="TOP" value="48"/>
<enum name="RIGHT" value="5"/>
<enum name="BOTTOM" value="80"/>
</attr>
<!-- 设置icon与文字间距 -->
<attr name="tl_iconMargin" format="dimension"/>
</declare-styleable>
<declare-styleable name="SegmentTabLayout">
<!-- indicator -->
<attr name="tl_indicator_color"/>
<attr name="tl_indicator_height"/>
<attr name="tl_indicator_margin_left"/>
<attr name="tl_indicator_margin_top"/>
<attr name="tl_indicator_margin_right"/>
<attr name="tl_indicator_margin_bottom"/>
<attr name="tl_indicator_corner_radius"/>
<attr name="tl_indicator_anim_enable"/>
<attr name="tl_indicator_anim_duration"/>
<attr name="tl_indicator_bounce_enable"/>
<!-- divider -->
<attr name="tl_divider_color"/>
<attr name="tl_divider_width"/>
<attr name="tl_divider_padding"/>
<!-- tab -->
<attr name="tl_tab_padding"/>
<attr name="tl_tab_space_equal"/>
<attr name="tl_tab_width"/>
<!-- title -->
<attr name="tl_textsize"/>
<attr name="tl_textSelectColor"/>
<attr name="tl_textUnselectColor"/>
<attr name="tl_textBold"/>
<attr name="tl_textAllCaps"/>
<attr name="tl_bar_color" format="color"/>
<attr name="tl_bar_stroke_color" format="color"/>
<attr name="tl_bar_stroke_width" format="dimension"/>
</declare-styleable>
<declare-styleable name="MsgView">
<!-- 圆角矩形背景色 -->
<attr name="mv_backgroundColor" format="color"/>
<!-- 圆角弧度,单位dp-->
<attr name="mv_cornerRadius" format="dimension"/>
<!-- 圆角弧度,单位dp-->
<attr name="mv_strokeWidth" format="dimension"/>
<!-- 圆角边框颜色-->
<attr name="mv_strokeColor" format="color"/>
<!-- 圆角弧度是高度一半-->
<attr name="mv_isRadiusHalfHeight" format="boolean"/>
<!-- 圆角矩形宽高相等,取较宽高中大值-->
<attr name="mv_isWidthHeightEqual" format="boolean"/>
</declare-styleable>
</resources>
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2015 H07000223
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# FlycoTabLayout
[](https://android-arsenal.com/details/1/2756)
#### [中文版](https://github.com/H07000223/FlycoTabLayout/blob/master/README_CN.md)
An Android TabLayout Lib has 3 kinds of TabLayout at present.
* SlidingTabLayout: deeply modified from [PagerSlidingTabStrip](https://github.com/jpardogo/PagerSlidingTabStrip).
* new added attribute
* new added kinds of indicators
* new added unread msg tip
* new added method for convenience
```java
/** no need to set titles in adapter */
public void setViewPager(ViewPager vp, String[] titles)
/** no need to initialize even adapter */
public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList<Fragment> fragments)
```
* CommonTabLayout:unlike SlidingTabLayout's dependence on ViewPager,it is a tabLayout without dependence on ViewPager and
can be used freely with other widgets together.
* support kinds of indicators and indicator animation
* support unread msg tip
* support icon and icon gravity.
* new added method for convenience
```java
/** support switch fragments itself */
public void setTabData(ArrayList<CustomTabEntity> tabEntitys, FragmentManager fm, int containerViewId, ArrayList<Fragment> fragments)
```
* SegmentTabLayout
## Demo



## Change Log
> 3.0.0 (2021-09-30)
- upgrade to AndroidX
- publish on Maven Central
## Gradle
```groovy
// AndroidX
dependencies {
implementation 'io.github.h07000223:flycoTabLayout:3.0.0'
}
// Old
dependencies{
compile 'com.android.support:support-v4:23.1.1'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
}
```
## Attributes
|name|format|description|
|:---:|:---:|:---:|
| tl_indicator_color | color |set indicator color
| tl_indicator_height | dimension |set indicator height
| tl_indicator_width | dimension |set indicator width
| tl_indicator_margin_left | dimension |set indicator margin,invalid when indicator width is greater than 0.
| tl_indicator_margin_top | dimension |set indicator margin,invalid when indicator width is greater than 0.
| tl_indicator_margin_right | dimension |set indicator margin,invalid when indicator width is greater than 0.
| tl_indicator_margin_bottom | dimension |set indicator margin,invalid when indicator width is greater than 0.
| tl_indicator_corner_radius | dimension |set indicator corner radius
| tl_indicator_gravity | enum |set indicator gravity TOP or BOTTOM.
| tl_indicator_style | enum |set indicator style NORMAL or TRIANGLE or BLOCK
| tl_underline_color | color |set underline color
| tl_underline_height | dimension |set underline height
| tl_underline_gravity | enum |set underline gravity TOP or BOTTOM
| tl_divider_color | color |set divider color
| tl_divider_width | dimension |set divider width
| tl_divider_padding |dimension| set divider paddingTop and paddingBottom
| tl_tab_padding |dimension| set tab paddingLeft and paddingRight
| tl_tab_space_equal |boolean| set tab space equal
| tl_tab_width |dimension| set tab width
| tl_textsize |dimension| set text size
| tl_textSelectColor |color| set text select color
| tl_textUnselectColor |color| set text unselect color
| tl_textBold |boolean| set text is bold
| tl_iconWidth |dimension| set icon width(only for CommonTabLayout)
| tl_iconHeight |dimension|set icon height(only for CommonTabLayout)
| tl_iconVisible |boolean| set icon is visible(only for CommonTabLayout)
| tl_iconGravity |enum| set icon gravity LEFT or TOP or RIGHT or BOTTOM(only for CommonTabLayout)
| tl_iconMargin |dimension| set icon margin with text(only for CommonTabLayout)
| tl_indicator_anim_enable |boolean| set indicator support animation(only for CommonTabLayout)
| tl_indicator_anim_duration |integer| set indicator animation duration(only for CommonTabLayout)
| tl_indicator_bounce_enable |boolean| set indicator aniamtion with bounce effect(only for CommonTabLayout)
| tl_indicator_width_equal_title |boolean| set indicator width same as text(only for SlidingTabLayout)
## Dependence
* [NineOldAndroids](https://github.com/JakeWharton/NineOldAndroids)
* [FlycoRoundView](https://github.com/H07000223/FlycoRoundView)
## Thanks
* [PagerSlidingTabStrip](https://github.com/jpardogo/PagerSlidingTabStrip)
================================================
FILE: README_CN.md
================================================
# FlycoTabLayout
[](https://android-arsenal.com/details/1/2756)
一个Android TabLayout库,目前有3个TabLayout
* SlidingTabLayout:参照[PagerSlidingTabStrip](https://github.com/jpardogo/PagerSlidingTabStrip)进行大量修改.
* 新增部分属性
* 新增支持多种Indicator显示器
* 新增支持未读消息显示
* 新增方法for懒癌患者
```java
/** 关联ViewPager,用于不想在ViewPager适配器中设置titles数据的情况 */
public void setViewPager(ViewPager vp, String[] titles)
/** 关联ViewPager,用于连适配器都不想自己实例化的情况 */
public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList<Fragment> fragments)
```
* CommonTabLayout:不同于SlidingTabLayout对ViewPager依赖,它是一个不依赖ViewPager可以与其他控件自由搭配使用的TabLayout.
* 支持多种Indicator显示器,以及Indicator动画
* 支持未读消息显示
* 支持Icon以及Icon位置
* 新增方法for懒癌患者
```java
/** 关联数据支持同时切换fragments */
public void setTabData(ArrayList<CustomTabEntity> tabEntitys, FragmentManager fm, int containerViewId, ArrayList<Fragment> fragments)
```
* SegmentTabLayout
## Demo



## Change Log
> 3.0.0 (2021-09-30)
- 升级到AndroidX
- 发布到Maven
## Gradle
```groovy
// AndroidX
dependencies {
implementation 'io.github.h07000223:flycoTabLayout:3.0.0'
}
// Old
dependencies{
compile 'com.android.support:support-v4:23.1.1'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
}
```
## Attributes
|name|format|description|
|:---:|:---:|:---:|
| tl_indicator_color | color |设置显示器颜色
| tl_indicator_height | dimension |设置显示器高度
| tl_indicator_width | dimension |设置显示器固定宽度
| tl_indicator_margin_left | dimension |设置显示器margin,当indicator_width大于0,无效
| tl_indicator_margin_top | dimension |设置显示器margin,当indicator_width大于0,无效
| tl_indicator_margin_right | dimension |设置显示器margin,当indicator_width大于0,无效
| tl_indicator_margin_bottom | dimension |设置显示器margin,当indicator_width大于0,无效
| tl_indicator_corner_radius | dimension |设置显示器圆角弧度
| tl_indicator_gravity | enum |设置显示器上方(TOP)还是下方(BOTTOM),只对常规显示器有用
| tl_indicator_style | enum |设置显示器为常规(NORMAL)或三角形(TRIANGLE)或背景色块(BLOCK)
| tl_underline_color | color |设置下划线颜色
| tl_underline_height | dimension |设置下划线高度
| tl_underline_gravity | enum |设置下划线上方(TOP)还是下方(BOTTOM)
| tl_divider_color | color |设置分割线颜色
| tl_divider_width | dimension |设置分割线宽度
| tl_divider_padding |dimension| 设置分割线的paddingTop和paddingBottom
| tl_tab_padding |dimension| 设置tab的paddingLeft和paddingRight
| tl_tab_space_equal |boolean| 设置tab大小等分
| tl_tab_width |dimension| 设置tab固定大小
| tl_textsize |dimension| 设置字体大小
| tl_textSelectColor |color| 设置字体选中颜色
| tl_textUnselectColor |color| 设置字体未选中颜色
| tl_textBold |boolean| 设置字体加粗
| tl_iconWidth |dimension| 设置icon宽度(仅支持CommonTabLayout)
| tl_iconHeight |dimension|设置icon高度(仅支持CommonTabLayout)
| tl_iconVisible |boolean| 设置icon是否可见(仅支持CommonTabLayout)
| tl_iconGravity |enum| 设置icon显示位置,对应Gravity中常量值,左上右下(仅支持CommonTabLayout)
| tl_iconMargin |dimension| 设置icon与文字间距(仅支持CommonTabLayout)
| tl_indicator_anim_enable |boolean| 设置显示器支持动画(only for CommonTabLayout)
| tl_indicator_anim_duration |integer| 设置显示器动画时间(only for CommonTabLayout)
| tl_indicator_bounce_enable |boolean| 设置显示器支持动画回弹效果(only for CommonTabLayout)
| tl_indicator_width_equal_title |boolean| 设置显示器与标题一样长(only for SlidingTabLayout)
## Dependence
* [NineOldAndroids](https://github.com/JakeWharton/NineOldAndroids)
* [FlycoRoundView](https://github.com/H07000223/FlycoRoundView)
## Thanks
* [PagerSlidingTabStrip](https://github.com/jpardogo/PagerSlidingTabStrip)
================================================
FILE: app/.gitignore
================================================
/build
================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.flyco.tablayoutsamples"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation support.appcompat
implementation support.v4
implementation support.design
// implementation project(':FlycoTabLayout_Lib')
implementation 'io.github.h07000223:flycoTabLayout:3.0.0'
}
================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/lihui/work/AndroidStudio/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: app/src/main/AndroidManifest.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="com.flyco.tablayoutsamples"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<activity
android:name=".ui.SimpleHomeActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".ui.CommonTabActivity"
android:screenOrientation="portrait"/>
<activity
android:name=".ui.SlidingTabActivity"
android:screenOrientation="portrait"/>
<activity
android:name=".ui.SegmentTabActivity"
android:screenOrientation="portrait"/>
</application>
</manifest>
================================================
FILE: app/src/main/java/com/flyco/tablayoutsamples/adapter/SimpleHomeAdapter.java
================================================
package com.flyco.tablayoutsamples.adapter;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class SimpleHomeAdapter extends BaseAdapter {
private Context mContext;
private String[] mItems;
private DisplayMetrics mDisplayMetrics;
public SimpleHomeAdapter(Context context, String[] items) {
this.mContext = context;
this.mItems = items;
mDisplayMetrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(mDisplayMetrics);
}
@Override
public int getCount() {
return mItems.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int padding = (int) (mDisplayMetrics.density * 10);
TextView tv = new TextView(mContext);
tv.setText(mItems[position]);
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
tv.setTextColor(Color.parseColor("#468ED0"));
// tv.setGravity(Gravity.CENTER);
tv.setPadding(padding, padding, padding, padding);
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
AbsListView.LayoutParams.WRAP_CONTENT);
tv.setLayoutParams(lp);
return tv;
}
}
================================================
FILE: app/src/main/java/com/flyco/tablayoutsamples/entity/TabEntity.java
================================================
package com.flyco.tablayoutsamples.entity;
import com.flyco.tablayout.listener.CustomTabEntity;
public class TabEntity implements CustomTabEntity {
public String title;
public int selectedIcon;
public int unSelectedIcon;
public TabEntity(String title, int selectedIcon, int unSelectedIcon) {
this.title = title;
this.selectedIcon = selectedIcon;
this.unSelectedIcon = unSelectedIcon;
}
@Override
public String getTabTitle() {
return title;
}
@Override
public int getTabSelectedIcon() {
return selectedIcon;
}
@Override
public int getTabUnselectedIcon() {
return unSelectedIcon;
}
}
================================================
FILE: app/src/main/java/com/flyco/tablayoutsamples/ui/CommonTabActivity.java
================================================
package com.flyco.tablayoutsamples.ui;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.flyco.tablayout.utils.UnreadMsgUtils;
import com.flyco.tablayout.widget.MsgView;
import com.flyco.tablayoutsamples.R;
import com.flyco.tablayoutsamples.entity.TabEntity;
import com.flyco.tablayoutsamples.utils.ViewFindUtils;
import java.util.ArrayList;
import java.util.Random;
public class CommonTabActivity extends AppCompatActivity {
private Context mContext = this;
private ArrayList<Fragment> mFragments = new ArrayList<>();
private ArrayList<Fragment> mFragments2 = new ArrayList<>();
private String[] mTitles = {"首页", "消息", "联系人", "更多"};
private int[] mIconUnselectIds = {
R.mipmap.tab_home_unselect, R.mipmap.tab_speech_unselect,
R.mipmap.tab_contact_unselect, R.mipmap.tab_more_unselect};
private int[] mIconSelectIds = {
R.mipmap.tab_home_select, R.mipmap.tab_speech_select,
R.mipmap.tab_contact_select, R.mipmap.tab_more_select};
private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
private View mDecorView;
private ViewPager mViewPager;
private CommonTabLayout mTabLayout_1;
private CommonTabLayout mTabLayout_2;
private CommonTabLayout mTabLayout_3;
private CommonTabLayout mTabLayout_4;
private CommonTabLayout mTabLayout_5;
private CommonTabLayout mTabLayout_6;
private CommonTabLayout mTabLayout_7;
private CommonTabLayout mTabLayout_8;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_common_tab);
for (String title : mTitles) {
mFragments.add(SimpleCardFragment.getInstance("Switch ViewPager " + title));
mFragments2.add(SimpleCardFragment.getInstance("Switch Fragment " + title));
}
for (int i = 0; i < mTitles.length; i++) {
mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconUnselectIds[i]));
}
mDecorView = getWindow().getDecorView();
mViewPager = ViewFindUtils.find(mDecorView, R.id.vp_2);
mViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
/** with nothing */
mTabLayout_1 = ViewFindUtils.find(mDecorView, R.id.tl_1);
/** with ViewPager */
mTabLayout_2 = ViewFindUtils.find(mDecorView, R.id.tl_2);
/** with Fragments */
mTabLayout_3 = ViewFindUtils.find(mDecorView, R.id.tl_3);
/** indicator固定宽度 */
mTabLayout_4 = ViewFindUtils.find(mDecorView, R.id.tl_4);
/** indicator固定宽度 */
mTabLayout_5 = ViewFindUtils.find(mDecorView, R.id.tl_5);
/** indicator矩形圆角 */
mTabLayout_6 = ViewFindUtils.find(mDecorView, R.id.tl_6);
/** indicator三角形 */
mTabLayout_7 = ViewFindUtils.find(mDecorView, R.id.tl_7);
/** indicator圆角色块 */
mTabLayout_8 = ViewFindUtils.find(mDecorView, R.id.tl_8);
mTabLayout_1.setTabData(mTabEntities);
tl_2();
mTabLayout_3.setTabData(mTabEntities, this, R.id.fl_change, mFragments2);
mTabLayout_4.setTabData(mTabEntities);
mTabLayout_5.setTabData(mTabEntities);
mTabLayout_6.setTabData(mTabEntities);
mTabLayout_7.setTabData(mTabEntities);
mTabLayout_8.setTabData(mTabEntities);
mTabLayout_3.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelect(int position) {
mTabLayout_1.setCurrentTab(position);
mTabLayout_2.setCurrentTab(position);
mTabLayout_4.setCurrentTab(position);
mTabLayout_5.setCurrentTab(position);
mTabLayout_6.setCurrentTab(position);
mTabLayout_7.setCurrentTab(position);
mTabLayout_8.setCurrentTab(position);
}
@Override
public void onTabReselect(int position) {
}
});
mTabLayout_8.setCurrentTab(2);
mTabLayout_3.setCurrentTab(1);
//显示未读红点
mTabLayout_1.showDot(2);
mTabLayout_3.showDot(1);
mTabLayout_4.showDot(1);
//两位数
mTabLayout_2.showMsg(0, 55);
mTabLayout_2.setMsgMargin(0, -5, 5);
//三位数
mTabLayout_2.showMsg(1, 100);
mTabLayout_2.setMsgMargin(1, -5, 5);
//设置未读消息红点
mTabLayout_2.showDot(2);
MsgView rtv_2_2 = mTabLayout_2.getMsgView(2);
if (rtv_2_2 != null) {
UnreadMsgUtils.setSize(rtv_2_2, dp2px(7.5f));
}
//设置未读消息背景
mTabLayout_2.showMsg(3, 5);
mTabLayout_2.setMsgMargin(3, 0, 5);
MsgView rtv_2_3 = mTabLayout_2.getMsgView(3);
if (rtv_2_3 != null) {
rtv_2_3.setBackgroundColor(Color.parseColor("#6D8FB0"));
}
}
Random mRandom = new Random();
private void tl_2() {
mTabLayout_2.setTabData(mTabEntities);
mTabLayout_2.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelect(int position) {
mViewPager.setCurrentItem(position);
}
@Override
public void onTabReselect(int position) {
if (position == 0) {
mTabLayout_2.showMsg(0, mRandom.nextInt(100) + 1);
// UnreadMsgUtils.show(mTabLayout_2.getMsgView(0), mRandom.nextInt(100) + 1);
}
}
});
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
mTabLayout_2.setCurrentTab(position);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
mViewPager.setCurrentItem(1);
}
private class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return mFragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return mTitles[position];
}
@Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
}
protected int dp2px(float dp) {
final float scale = mContext.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
}
================================================
FILE: app/src/main/java/com/flyco/tablayoutsamples/ui/SegmentTabActivity.java
================================================
package com.flyco.tablayoutsamples.ui;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.flyco.tablayout.SegmentTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.flyco.tablayout.widget.MsgView;
import com.flyco.tablayoutsamples.R;
import com.flyco.tablayoutsamples.utils.ViewFindUtils;
import java.util.ArrayList;
public class SegmentTabActivity extends AppCompatActivity {
private ArrayList<Fragment> mFragments = new ArrayList<>();
private ArrayList<Fragment> mFragments2 = new ArrayList<>();
private String[] mTitles = {"首页", "消息"};
private String[] mTitles_2 = {"首页", "消息", "联系人"};
private String[] mTitles_3 = {"首页", "消息", "联系人", "更多"};
private View mDecorView;
private SegmentTabLayout mTabLayout_3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_segment_tab);
for (String title : mTitles_3) {
mFragments.add(SimpleCardFragment.getInstance("Switch ViewPager " + title));
}
for (String title : mTitles_2) {
mFragments2.add(SimpleCardFragment.getInstance("Switch Fragment " + title));
}
mDecorView = getWindow().getDecorView();
SegmentTabLayout tabLayout_1 = ViewFindUtils.find(mDecorView, R.id.tl_1);
SegmentTabLayout tabLayout_2 = ViewFindUtils.find(mDecorView, R.id.tl_2);
mTabLayout_3 = ViewFindUtils.find(mDecorView, R.id.tl_3);
SegmentTabLayout tabLayout_4 = ViewFindUtils.find(mDecorView, R.id.tl_4);
SegmentTabLayout tabLayout_5 = ViewFindUtils.find(mDecorView, R.id.tl_5);
tabLayout_1.setTabData(mTitles);
tabLayout_2.setTabData(mTitles_2);
tl_3();
tabLayout_4.setTabData(mTitles_2, this, R.id.fl_change, mFragments2);
tabLayout_5.setTabData(mTitles_3);
//显示未读红点
tabLayout_1.showDot(2);
tabLayout_2.showDot(2);
mTabLayout_3.showDot(1);
tabLayout_4.showDot(1);
//设置未读消息红点
mTabLayout_3.showDot(2);
MsgView rtv_3_2 = mTabLayout_3.getMsgView(2);
if (rtv_3_2 != null) {
rtv_3_2.setBackgroundColor(Color.parseColor("#6D8FB0"));
}
}
private void tl_3() {
final ViewPager vp_3 = ViewFindUtils.find(mDecorView, R.id.vp_2);
vp_3.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
mTabLayout_3.setTabData(mTitles_3);
mTabLayout_3.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelect(int position) {
vp_3.setCurrentItem(position);
}
@Override
public void onTabReselect(int position) {
}
});
vp_3.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
mTabLayout_3.setCurrentTab(position);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
vp_3.setCurrentItem(1);
}
private class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return mFragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return mTitles_3[position];
}
@Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
}
}
================================================
FILE: app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleCardFragment.java
================================================
package com.flyco.tablayoutsamples.ui;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.flyco.tablayoutsamples.R;
@SuppressLint("ValidFragment")
public class SimpleCardFragment extends Fragment {
private String mTitle;
public static SimpleCardFragment getInstance(String title) {
SimpleCardFragment sf = new SimpleCardFragment();
sf.mTitle = title;
return sf;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fr_simple_card, null);
TextView card_title_tv = (TextView) v.findViewById(R.id.card_title_tv);
card_title_tv.setText(mTitle);
return v;
}
}
================================================
FILE: app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleHomeActivity.java
================================================
package com.flyco.tablayoutsamples.ui;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import com.flyco.tablayoutsamples.adapter.SimpleHomeAdapter;
public class SimpleHomeActivity extends AppCompatActivity {
private Context mContext = this;
private final String[] mItems = {"SlidingTabLayout", "CommonTabLayout", "SegmentTabLayout"};
private final Class<?>[] mClasses = {SlidingTabActivity.class, CommonTabActivity.class,
SegmentTabActivity.class};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView lv = new ListView(mContext);
lv.setCacheColorHint(Color.TRANSPARENT);
lv.setFadingEdgeLength(0);
lv.setAdapter(new SimpleHomeAdapter(mContext, mItems));
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(mContext, mClasses[position]);
startActivity(intent);
}
});
setContentView(lv);
}
}
================================================
FILE: app/src/main/java/com/flyco/tablayoutsamples/ui/SlidingTabActivity.java
================================================
package com.flyco.tablayoutsamples.ui;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.flyco.tablayout.widget.MsgView;
import com.flyco.tablayoutsamples.R;
import com.flyco.tablayoutsamples.utils.ViewFindUtils;
import java.util.ArrayList;
public class SlidingTabActivity extends AppCompatActivity implements OnTabSelectListener {
private Context mContext = this;
private ArrayList<Fragment> mFragments = new ArrayList<>();
private final String[] mTitles = {
"热门", "iOS", "Android"
, "前端", "后端", "设计", "工具资源"
};
private MyPagerAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sliding_tab);
for (String title : mTitles) {
mFragments.add(SimpleCardFragment.getInstance(title));
}
View decorView = getWindow().getDecorView();
ViewPager vp = ViewFindUtils.find(decorView, R.id.vp);
mAdapter = new MyPagerAdapter(getSupportFragmentManager());
vp.setAdapter(mAdapter);
/** 默认 */
SlidingTabLayout tabLayout_1 = ViewFindUtils.find(decorView, R.id.tl_1);
/**自定义部分属性*/
SlidingTabLayout tabLayout_2 = ViewFindUtils.find(decorView, R.id.tl_2);
/** 字体加粗,大写 */
SlidingTabLayout tabLayout_3 = ViewFindUtils.find(decorView, R.id.tl_3);
/** tab固定宽度 */
SlidingTabLayout tabLayout_4 = ViewFindUtils.find(decorView, R.id.tl_4);
/** indicator固定宽度 */
SlidingTabLayout tabLayout_5 = ViewFindUtils.find(decorView, R.id.tl_5);
/** indicator圆 */
SlidingTabLayout tabLayout_6 = ViewFindUtils.find(decorView, R.id.tl_6);
/** indicator矩形圆角 */
final SlidingTabLayout tabLayout_7 = ViewFindUtils.find(decorView, R.id.tl_7);
/** indicator三角形 */
SlidingTabLayout tabLayout_8 = ViewFindUtils.find(decorView, R.id.tl_8);
/** indicator圆角色块 */
SlidingTabLayout tabLayout_9 = ViewFindUtils.find(decorView, R.id.tl_9);
/** indicator圆角色块 */
SlidingTabLayout tabLayout_10 = ViewFindUtils.find(decorView, R.id.tl_10);
tabLayout_1.setViewPager(vp);
tabLayout_2.setViewPager(vp);
tabLayout_2.setOnTabSelectListener(this);
tabLayout_3.setViewPager(vp);
tabLayout_4.setViewPager(vp);
tabLayout_5.setViewPager(vp);
tabLayout_6.setViewPager(vp);
tabLayout_7.setViewPager(vp, mTitles);
tabLayout_8.setViewPager(vp, mTitles, this, mFragments);
tabLayout_9.setViewPager(vp);
tabLayout_10.setViewPager(vp);
vp.setCurrentItem(4);
tabLayout_1.showDot(4);
tabLayout_3.showDot(4);
tabLayout_2.showDot(4);
tabLayout_2.showMsg(3, 5);
tabLayout_2.setMsgMargin(3, 0, 10);
MsgView rtv_2_3 = tabLayout_2.getMsgView(3);
if (rtv_2_3 != null) {
rtv_2_3.setBackgroundColor(Color.parseColor("#6D8FB0"));
}
tabLayout_2.showMsg(5, 5);
tabLayout_2.setMsgMargin(5, 0, 10);
// tabLayout_7.setOnTabSelectListener(new OnTabSelectListener() {
// @Override
// public void onTabSelect(int position) {
// Toast.makeText(mContext, "onTabSelect&position--->" + position, Toast.LENGTH_SHORT).show();
// }
//
// @Override
// public void onTabReselect(int position) {
// mFragments.add(SimpleCardFragment.getInstance("后端"));
// mAdapter.notifyDataSetChanged();
// tabLayout_7.addNewTab("后端");
// }
// });
}
@Override
public void onTabSelect(int position) {
Toast.makeText(mContext, "onTabSelect&position--->" + position, Toast.LENGTH_SHORT).show();
}
@Override
public void onTabReselect(int position) {
Toast.makeText(mContext, "onTabReselect&position--->" + position, Toast.LENGTH_SHORT).show();
}
private class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return mFragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return mTitles[position];
}
@Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
}
}
================================================
FILE: app/src/main/java/com/flyco/tablayoutsamples/utils/ViewFindUtils.java
================================================
package com.flyco.tablayoutsamples.utils;
import android.util.SparseArray;
import android.view.View;
@SuppressWarnings({"unchecked"})
public class ViewFindUtils {
/**
* ViewHolder简洁写法,避免适配器中重复定义ViewHolder,减少代码量 用法:
*
* <pre>
* if (convertView == null)
* {
* convertView = View.inflate(context, R.layout.ad_demo, null);
* }
* TextView tv_demo = ViewHolderUtils.get(convertView, R.id.tv_demo);
* ImageView iv_demo = ViewHolderUtils.get(convertView, R.id.iv_demo);
* </pre>
*/
public static <T extends View> T hold(View view, int id) {
SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
if (viewHolder == null) {
viewHolder = new SparseArray<View>();
view.setTag(viewHolder);
}
View childView = viewHolder.get(id);
if (childView == null) {
childView = view.findViewById(id);
viewHolder.put(id, childView);
}
return (T) childView;
}
/**
* 替代findviewById方法
*/
public static <T extends View> T find(View view, int id) {
return (T) view.findViewById(id);
}
}
================================================
FILE: app/src/main/res/layout/activity_common_tab.xml
================================================
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tl="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#eeeeee"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.flyco.tablayout.CommonTabLayout
android:id="@+id/tl_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingBottom="5dp"
android:paddingTop="5dp"
tl:tl_indicator_color="#2C97DE"
tl:tl_textSelectColor="#2C97DE"
tl:tl_textUnselectColor="#66000000"
tl:tl_underline_color="#DDDDDD"
tl:tl_underline_height="1dp"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/vp_2"
android:layout_width="match_parent"
android:layout_height="84dp"/>
<com.flyco.tablayout.CommonTabLayout
android:id="@+id/tl_2"
android:layout_width="match_parent"
android:layout_height="54dp"
android:background="#ffffff"
tl:tl_iconHeight="23dp"
tl:tl_iconWidth="23dp"
tl:tl_indicator_color="#2C97DE"
tl:tl_indicator_height="0dp"
tl:tl_textSelectColor="#2C97DE"
tl:tl_textUnselectColor="#66000000"
tl:tl_textsize="12sp"
tl:tl_underline_color="#DDDDDD"
tl:tl_underline_height="1dp"/>
<FrameLayout
android:id="@+id/fl_change"
android:layout_width="match_parent"
android:layout_height="84dp">
</FrameLayout>
<com.flyco.tablayout.CommonTabLayout
android:id="@+id/tl_3"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#ffffff"
tl:tl_iconGravity="LEFT"
tl:tl_iconHeight="18dp"
tl:tl_iconMargin="5dp"
tl:tl_iconWidth="18dp"
tl:tl_indicator_bounce_enable="false"
tl:tl_indicator_color="#2C97DE"
tl:tl_indicator_gravity="TOP"
tl:tl_textSelectColor="#2C97DE"
tl:tl_textUnselectColor="#66000000"
tl:tl_textsize="15sp"
tl:tl_underline_color="#DDDDDD"
tl:tl_underline_gravity="TOP"
tl:tl_underline_height="1dp"/>
<com.flyco.tablayout.CommonTabLayout
android:id="@+id/tl_4"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#F6CE59"
tl:tl_iconVisible="false"
tl:tl_textBold="SELECT"
tl:tl_indicator_width="10dp"
tl:tl_textsize="14sp"/>
<com.flyco.tablayout.CommonTabLayout
tl:tl_textBold="BOTH"
android:id="@+id/tl_5"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#EC7263"
tl:tl_iconVisible="false"
tl:tl_indicator_corner_radius="2dp"
tl:tl_indicator_height="4dp"
tl:tl_indicator_width="4dp"
tl:tl_textsize="14sp"/>
<com.flyco.tablayout.CommonTabLayout
android:id="@+id/tl_6"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#57385C"
tl:tl_iconVisible="false"
tl:tl_indicator_corner_radius="1.5dp"
tl:tl_indicator_height="3dp"
tl:tl_indicator_width="10dp"
tl:tl_textsize="14sp"/>
<com.flyco.tablayout.CommonTabLayout
android:id="@+id/tl_7"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#E45171"
tl:tl_iconVisible="false"
tl:tl_indicator_color="#eeeeee"
tl:tl_indicator_corner_radius="1.5dp"
tl:tl_indicator_height="3dp"
tl:tl_indicator_style="TRIANGLE"
tl:tl_indicator_width="10dp"
tl:tl_textsize="14sp"/>
<com.flyco.tablayout.CommonTabLayout
android:id="@+id/tl_8"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#6D8FB0"
android:paddingLeft="5dp"
android:paddingRight="5dp"
tl:tl_iconVisible="false"
tl:tl_indicator_margin_left="5dp"
tl:tl_indicator_margin_right="5dp"
tl:tl_indicator_style="BLOCK"
tl:tl_textsize="14sp"/>
</LinearLayout>
</ScrollView>
================================================
FILE: app/src/main/res/layout/activity_segment_tab.xml
================================================
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tl="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eeeeee"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.flyco.tablayout.SegmentTabLayout
android:id="@+id/tl_1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
tl:tl_bar_color="#ffffff"
tl:tl_indicator_color="#2C97DE"
tl:tl_indicator_corner_radius="8dp"
tl:tl_tab_padding="20dp"/>
<com.flyco.tablayout.SegmentTabLayout
android:id="@+id/tl_2"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
tl:tl_indicator_anim_enable="true"
tl:tl_indicator_bounce_enable="false"
tl:tl_indicator_color="#009688"
tl:tl_tab_padding="20dp"/>
<com.flyco.tablayout.SegmentTabLayout
android:id="@+id/tl_3"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginTop="10dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
tl:tl_bar_color="#ffffff"
tl:tl_indicator_anim_enable="true"
tl:tl_indicator_color="#F6CE59"
tl:tl_indicator_margin_bottom="2dp"
tl:tl_indicator_margin_left="2dp"
tl:tl_indicator_margin_right="2dp"
tl:tl_indicator_margin_top="2dp"
tl:tl_textBold="SELECT"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/vp_2"
android:layout_width="match_parent"
android:layout_height="84dp"/>
<com.flyco.tablayout.SegmentTabLayout
android:id="@+id/tl_4"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_gravity="center_horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
tl:tl_bar_color="#ffffff"
tl:tl_indicator_color="#EC7263"
tl:tl_indicator_margin_bottom="2dp"
tl:tl_indicator_margin_left="2dp"
tl:tl_indicator_margin_right="2dp"
tl:tl_indicator_margin_top="2dp"
tl:tl_tab_width="80dp"
tl:tl_textBold="BOTH"/>
<FrameLayout
android:id="@+id/fl_change"
android:layout_width="match_parent"
android:layout_height="84dp"/>
<com.flyco.tablayout.SegmentTabLayout
android:id="@+id/tl_5"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_gravity="center_horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp"
tl:tl_indicator_anim_enable="true"
tl:tl_indicator_bounce_enable="false"
tl:tl_indicator_margin_bottom="2dp"
tl:tl_indicator_margin_left="2dp"
tl:tl_indicator_margin_right="2dp"
tl:tl_indicator_margin_top="2dp"
tl:tl_tab_space_equal="true"/>
</LinearLayout>
</ScrollView>
================================================
FILE: app/src/main/res/layout/activity_sliding_tab.xml
================================================
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tl="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#eeeeee"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/tl_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#666666"
android:paddingBottom="15dp"
android:paddingTop="15dp"
tl:tl_indicator_gravity="TOP"
tl:tl_textBold="SELECT"
tl:tl_underline_color="#1A000000"
tl:tl_underline_gravity="TOP"
tl:tl_underline_height="1dp"/>
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/tl_2"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#EEEEEE"
tl:tl_divider_color="#1A000000"
tl:tl_divider_padding="13dp"
tl:tl_divider_width="1dp"
tl:tl_indicator_color="#000000"
tl:tl_indicator_height="1.5dp"
tl:tl_indicator_width_equal_title="true"
tl:tl_tab_padding="22dp"
tl:tl_tab_space_equal="true"
tl:tl_textSelectColor="#000000"
tl:tl_textUnselectColor="#66000000"
tl:tl_underline_color="#1A000000"
tl:tl_underline_height="1dp"/>
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/tl_3"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#3F9FE0"
tl:tl_textAllCaps="true"
tl:tl_textBold="BOTH"
tl:tl_textsize="14sp"/>
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/tl_4"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#009688"
tl:tl_tab_padding="0dp"
tl:tl_tab_width="95dp"
tl:tl_textsize="15sp"/>
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/tl_5"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#F6CE59"
tl:tl_indicator_width="10dp"/>
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/tl_6"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#EC7263"
tl:tl_indicator_corner_radius="2dp"
tl:tl_indicator_height="4dp"
tl:tl_indicator_width="4dp"/>
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/tl_7"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#57385C"
tl:tl_indicator_corner_radius="1.5dp"
tl:tl_indicator_height="3dp"
tl:tl_indicator_width="10dp"/>
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/tl_8"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#E45171"
tl:tl_indicator_color="#eeeeee"
tl:tl_indicator_style="TRIANGLE"/>
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/tl_9"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#6D8FB0"
android:paddingLeft="5dp"
android:paddingRight="5dp"
tl:tl_indicator_margin_left="2dp"
tl:tl_indicator_margin_right="2dp"
tl:tl_indicator_style="BLOCK"/>
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/tl_10"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#222831"
android:paddingLeft="5dp"
android:paddingRight="5dp"
tl:tl_indicator_color="#393E46"
tl:tl_indicator_corner_radius="5dp"
tl:tl_indicator_margin_left="2dp"
tl:tl_indicator_margin_right="2dp"
tl:tl_indicator_style="BLOCK"/>
</LinearLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="84dp"/>
</LinearLayout>
</ScrollView>
================================================
FILE: app/src/main/res/layout/fr_simple_card.xml
================================================
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/card_title_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:background="@drawable/background_card"
android:gravity="center"
android:textSize="18sp"/>
</RelativeLayout>
================================================
FILE: app/src/main/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#8BC34A</color>
<color name="colorPrimaryDark">#689F38</color>
<color name="colorAccent">#FF4081</color>
<color name="textColorPrimary">#FFFFFF</color>
</resources>
================================================
FILE: app/src/main/res/values/strings.xml
================================================
<resources>
<string name="app_name">FlycoTabLayout</string>
</resources>
================================================
FILE: app/src/main/res/values/styles.xml
================================================
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorPrimary">@color/textColorPrimary</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
</resources>
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: 'dependencies.gradle'
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: dependencies.gradle
================================================
ext {
minSdkVersion = 16
targetSdkVersion = 29
compileSdkVersion = 29
buildToolsVersion = '29.0.2'
versionCode = 100
versionName = '1.0.0'
lifecycle_version = '2.3.1'
support = [
'v4' : "androidx.legacy:legacy-support-v4:1.0.0",
'annotations' : "androidx.annotation:annotation:1.1.0",
'appcompat' : "androidx.appcompat:appcompat:1.2.0",
'recyclerview' : "androidx.recyclerview:recyclerview:1.1.0",
'design' : "com.google.android.material:material:1.2.1",
'constraintlayout' : "androidx.constraintlayout:constraintlayout:2.0.4",
]
arch_lifecycle = [
'viewmodel' : "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version",
'livedata' : "androidx.lifecycle:lifecycle-livedata:$lifecycle_version",
'lifecycle' : "androidx.lifecycle:lifecycle-runtime:$lifecycle_version",
'lifecycle-ktx' : "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version",
'lifecycle-process' : "androidx.lifecycle:lifecycle-process:$lifecycle_version",
]
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Wed Nov 25 18:19:50 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useAndroidX=true
# com.flyco.tablayout:flycoTabLayout:3.0.0
GROUP=io.github.h07000223
POM_ARTIFACT_ID=flycoTabLayout
VERSION_NAME=3.0.0
POM_NAME=FlycoTabLayout
POM_DESCRIPTION=Android TabLayout Library
POM_INCEPTION_YEAR=2021
POM_URL=https://github.com/H07000223/FlycoTabLayout
POM_LICENSE_NAME=The Apache Software License, Version 2.0
POM_LICENSE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENSE_DIST=repo
POM_SCM_URL=https://github.com/H07000223/FlycoTabLayout
POM_SCM_CONNECTION=scm:git:git://github.com/H07000223/FlycoTabLayout.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://github.com/H07000223/FlycoTabLayout.git
POM_DEVELOPER_ID=H07000223
POM_DEVELOPER_NAME=H07000223
POM_DEVELOPER_URL=https://github.com/H07000223
# 密钥ID的后8位
signing.keyId=
# 密钥密码
signing.password=
signing.secretKeyRingFile=
# Sonatype账号&密码
mavenCentralUsername=
mavenCentralPassword=
================================================
FILE: gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: settings.gradle
================================================
include ':app', ':FlycoTabLayout_Lib'
gitextract_h399tfmj/ ├── .gitignore ├── CHNAGELOG.md ├── FlycoTabLayout_Lib/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── flyco/ │ │ └── tablayout/ │ │ ├── CommonTabLayout.java │ │ ├── SegmentTabLayout.java │ │ ├── SlidingTabLayout.java │ │ ├── listener/ │ │ │ ├── CustomTabEntity.java │ │ │ └── OnTabSelectListener.java │ │ ├── utils/ │ │ │ ├── FragmentChangeManager.java │ │ │ └── UnreadMsgUtils.java │ │ └── widget/ │ │ └── MsgView.java │ └── res/ │ ├── layout/ │ │ ├── layout_tab.xml │ │ ├── layout_tab_bottom.xml │ │ ├── layout_tab_left.xml │ │ ├── layout_tab_right.xml │ │ ├── layout_tab_segment.xml │ │ └── layout_tab_top.xml │ └── values/ │ └── attrs.xml ├── LICENSE ├── README.md ├── README_CN.md ├── app/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── flyco/ │ │ └── tablayoutsamples/ │ │ ├── adapter/ │ │ │ └── SimpleHomeAdapter.java │ │ ├── entity/ │ │ │ └── TabEntity.java │ │ ├── ui/ │ │ │ ├── CommonTabActivity.java │ │ │ ├── SegmentTabActivity.java │ │ │ ├── SimpleCardFragment.java │ │ │ ├── SimpleHomeActivity.java │ │ │ └── SlidingTabActivity.java │ │ └── utils/ │ │ └── ViewFindUtils.java │ └── res/ │ ├── layout/ │ │ ├── activity_common_tab.xml │ │ ├── activity_segment_tab.xml │ │ ├── activity_sliding_tab.xml │ │ └── fr_simple_card.xml │ └── values/ │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── dependencies.gradle ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle
SYMBOL INDEX (334 symbols across 16 files)
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java
class CommonTabLayout (line 39) | public class CommonTabLayout extends FrameLayout implements ValueAnimato...
method CommonTabLayout (line 112) | public CommonTabLayout(Context context) {
method CommonTabLayout (line 116) | public CommonTabLayout(Context context, AttributeSet attrs) {
method CommonTabLayout (line 120) | public CommonTabLayout(Context context, AttributeSet attrs, int defSty...
method obtainAttributes (line 149) | private void obtainAttributes(Context context, AttributeSet attrs) {
method setTabData (line 194) | public void setTabData(ArrayList<CustomTabEntity> tabEntitys) {
method setTabData (line 206) | public void setTabData(ArrayList<CustomTabEntity> tabEntitys, Fragment...
method notifyDataSetChanged (line 212) | public void notifyDataSetChanged() {
method addTab (line 235) | private void addTab(final int position, View tabView) {
method updateTabStyles (line 268) | private void updateTabStyles() {
method updateTabSelection (line 311) | private void updateTabSelection(int position) {
method calcOffset (line 326) | private void calcOffset() {
method calcIndicatorRect (line 353) | private void calcIndicatorRect() {
method onAnimationUpdate (line 371) | @Override
method onDraw (line 391) | @Override
method setCurrentTab (line 487) | public void setCurrentTab(int currentTab) {
method setIndicatorStyle (line 501) | public void setIndicatorStyle(int indicatorStyle) {
method setTabPadding (line 506) | public void setTabPadding(float tabPadding) {
method setTabSpaceEqual (line 511) | public void setTabSpaceEqual(boolean tabSpaceEqual) {
method setTabWidth (line 516) | public void setTabWidth(float tabWidth) {
method setIndicatorColor (line 521) | public void setIndicatorColor(int indicatorColor) {
method setIndicatorHeight (line 526) | public void setIndicatorHeight(float indicatorHeight) {
method setIndicatorWidth (line 531) | public void setIndicatorWidth(float indicatorWidth) {
method setIndicatorCornerRadius (line 536) | public void setIndicatorCornerRadius(float indicatorCornerRadius) {
method setIndicatorGravity (line 541) | public void setIndicatorGravity(int indicatorGravity) {
method setIndicatorMargin (line 546) | public void setIndicatorMargin(float indicatorMarginLeft, float indica...
method setIndicatorAnimDuration (line 555) | public void setIndicatorAnimDuration(long indicatorAnimDuration) {
method setIndicatorAnimEnable (line 559) | public void setIndicatorAnimEnable(boolean indicatorAnimEnable) {
method setIndicatorBounceEnable (line 563) | public void setIndicatorBounceEnable(boolean indicatorBounceEnable) {
method setUnderlineColor (line 567) | public void setUnderlineColor(int underlineColor) {
method setUnderlineHeight (line 572) | public void setUnderlineHeight(float underlineHeight) {
method setUnderlineGravity (line 577) | public void setUnderlineGravity(int underlineGravity) {
method setDividerColor (line 582) | public void setDividerColor(int dividerColor) {
method setDividerWidth (line 587) | public void setDividerWidth(float dividerWidth) {
method setDividerPadding (line 592) | public void setDividerPadding(float dividerPadding) {
method setTextsize (line 597) | public void setTextsize(float textsize) {
method setTextSelectColor (line 602) | public void setTextSelectColor(int textSelectColor) {
method setTextUnselectColor (line 607) | public void setTextUnselectColor(int textUnselectColor) {
method setTextBold (line 612) | public void setTextBold(int textBold) {
method setIconVisible (line 617) | public void setIconVisible(boolean iconVisible) {
method setIconGravity (line 622) | public void setIconGravity(int iconGravity) {
method setIconWidth (line 627) | public void setIconWidth(float iconWidth) {
method setIconHeight (line 632) | public void setIconHeight(float iconHeight) {
method setIconMargin (line 637) | public void setIconMargin(float iconMargin) {
method setTextAllCaps (line 642) | public void setTextAllCaps(boolean textAllCaps) {
method getTabCount (line 648) | public int getTabCount() {
method getCurrentTab (line 652) | public int getCurrentTab() {
method getIndicatorStyle (line 656) | public int getIndicatorStyle() {
method getTabPadding (line 660) | public float getTabPadding() {
method isTabSpaceEqual (line 664) | public boolean isTabSpaceEqual() {
method getTabWidth (line 668) | public float getTabWidth() {
method getIndicatorColor (line 672) | public int getIndicatorColor() {
method getIndicatorHeight (line 676) | public float getIndicatorHeight() {
method getIndicatorWidth (line 680) | public float getIndicatorWidth() {
method getIndicatorCornerRadius (line 684) | public float getIndicatorCornerRadius() {
method getIndicatorMarginLeft (line 688) | public float getIndicatorMarginLeft() {
method getIndicatorMarginTop (line 692) | public float getIndicatorMarginTop() {
method getIndicatorMarginRight (line 696) | public float getIndicatorMarginRight() {
method getIndicatorMarginBottom (line 700) | public float getIndicatorMarginBottom() {
method getIndicatorAnimDuration (line 704) | public long getIndicatorAnimDuration() {
method isIndicatorAnimEnable (line 708) | public boolean isIndicatorAnimEnable() {
method isIndicatorBounceEnable (line 712) | public boolean isIndicatorBounceEnable() {
method getUnderlineColor (line 716) | public int getUnderlineColor() {
method getUnderlineHeight (line 720) | public float getUnderlineHeight() {
method getDividerColor (line 724) | public int getDividerColor() {
method getDividerWidth (line 728) | public float getDividerWidth() {
method getDividerPadding (line 732) | public float getDividerPadding() {
method getTextsize (line 736) | public float getTextsize() {
method getTextSelectColor (line 740) | public int getTextSelectColor() {
method getTextUnselectColor (line 744) | public int getTextUnselectColor() {
method getTextBold (line 748) | public int getTextBold() {
method isTextAllCaps (line 752) | public boolean isTextAllCaps() {
method getIconGravity (line 756) | public int getIconGravity() {
method getIconWidth (line 760) | public float getIconWidth() {
method getIconHeight (line 764) | public float getIconHeight() {
method getIconMargin (line 768) | public float getIconMargin() {
method isIconVisible (line 772) | public boolean isIconVisible() {
method getIconView (line 777) | public ImageView getIconView(int tab) {
method getTitleView (line 783) | public TextView getTitleView(int tab) {
method showMsg (line 801) | public void showMsg(int position, int num) {
method showDot (line 831) | public void showDot(int position) {
method hideMsg (line 838) | public void hideMsg(int position) {
method setMsgMargin (line 855) | public void setMsgMargin(int position, float leftPadding, float bottom...
method getMsgView (line 890) | public MsgView getMsgView(int position) {
method setOnTabSelectListener (line 901) | public void setOnTabSelectListener(OnTabSelectListener listener) {
method onSaveInstanceState (line 906) | @Override
method onRestoreInstanceState (line 914) | @Override
class IndicatorPoint (line 927) | class IndicatorPoint {
class PointEvaluator (line 935) | class PointEvaluator implements TypeEvaluator<IndicatorPoint> {
method evaluate (line 936) | @Override
method dp2px (line 948) | protected int dp2px(float dp) {
method sp2px (line 953) | protected int sp2px(float sp) {
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SegmentTabLayout.java
class SegmentTabLayout (line 34) | public class SegmentTabLayout extends FrameLayout implements ValueAnimat...
method SegmentTabLayout (line 92) | public SegmentTabLayout(Context context) {
method SegmentTabLayout (line 96) | public SegmentTabLayout(Context context, AttributeSet attrs) {
method SegmentTabLayout (line 100) | public SegmentTabLayout(Context context, AttributeSet attrs, int defSt...
method obtainAttributes (line 129) | private void obtainAttributes(Context context, AttributeSet attrs) {
method setTabData (line 164) | public void setTabData(String[] titles) {
method setTabData (line 175) | public void setTabData(String[] titles, FragmentActivity fa, int conta...
method notifyDataSetChanged (line 181) | public void notifyDataSetChanged() {
method addTab (line 195) | private void addTab(final int position, View tabView) {
method updateTabStyles (line 226) | private void updateTabStyles() {
method updateTabSelection (line 246) | private void updateTabSelection(int position) {
method calcOffset (line 258) | private void calcOffset() {
method calcIndicatorRect (line 285) | private void calcIndicatorRect() {
method onAnimationUpdate (line 338) | @Override
method onDraw (line 348) | @Override
method setCurrentTab (line 405) | public void setCurrentTab(int currentTab) {
method setTabPadding (line 419) | public void setTabPadding(float tabPadding) {
method setTabSpaceEqual (line 424) | public void setTabSpaceEqual(boolean tabSpaceEqual) {
method setTabWidth (line 429) | public void setTabWidth(float tabWidth) {
method setIndicatorColor (line 434) | public void setIndicatorColor(int indicatorColor) {
method setIndicatorHeight (line 439) | public void setIndicatorHeight(float indicatorHeight) {
method setIndicatorCornerRadius (line 444) | public void setIndicatorCornerRadius(float indicatorCornerRadius) {
method setIndicatorMargin (line 449) | public void setIndicatorMargin(float indicatorMarginLeft, float indica...
method setIndicatorAnimDuration (line 458) | public void setIndicatorAnimDuration(long indicatorAnimDuration) {
method setIndicatorAnimEnable (line 462) | public void setIndicatorAnimEnable(boolean indicatorAnimEnable) {
method setIndicatorBounceEnable (line 466) | public void setIndicatorBounceEnable(boolean indicatorBounceEnable) {
method setDividerColor (line 470) | public void setDividerColor(int dividerColor) {
method setDividerWidth (line 475) | public void setDividerWidth(float dividerWidth) {
method setDividerPadding (line 480) | public void setDividerPadding(float dividerPadding) {
method setTextsize (line 485) | public void setTextsize(float textsize) {
method setTextSelectColor (line 490) | public void setTextSelectColor(int textSelectColor) {
method setTextUnselectColor (line 495) | public void setTextUnselectColor(int textUnselectColor) {
method setTextBold (line 500) | public void setTextBold(int textBold) {
method setTextAllCaps (line 505) | public void setTextAllCaps(boolean textAllCaps) {
method getTabCount (line 510) | public int getTabCount() {
method getCurrentTab (line 514) | public int getCurrentTab() {
method getTabPadding (line 518) | public float getTabPadding() {
method isTabSpaceEqual (line 522) | public boolean isTabSpaceEqual() {
method getTabWidth (line 526) | public float getTabWidth() {
method getIndicatorColor (line 530) | public int getIndicatorColor() {
method getIndicatorHeight (line 534) | public float getIndicatorHeight() {
method getIndicatorCornerRadius (line 538) | public float getIndicatorCornerRadius() {
method getIndicatorMarginLeft (line 542) | public float getIndicatorMarginLeft() {
method getIndicatorMarginTop (line 546) | public float getIndicatorMarginTop() {
method getIndicatorMarginRight (line 550) | public float getIndicatorMarginRight() {
method getIndicatorMarginBottom (line 554) | public float getIndicatorMarginBottom() {
method getIndicatorAnimDuration (line 558) | public long getIndicatorAnimDuration() {
method isIndicatorAnimEnable (line 562) | public boolean isIndicatorAnimEnable() {
method isIndicatorBounceEnable (line 566) | public boolean isIndicatorBounceEnable() {
method getDividerColor (line 570) | public int getDividerColor() {
method getDividerWidth (line 574) | public float getDividerWidth() {
method getDividerPadding (line 578) | public float getDividerPadding() {
method getTextsize (line 582) | public float getTextsize() {
method getTextSelectColor (line 586) | public int getTextSelectColor() {
method getTextUnselectColor (line 590) | public int getTextUnselectColor() {
method getTextBold (line 594) | public int getTextBold() {
method isTextAllCaps (line 598) | public boolean isTextAllCaps() {
method getTitleView (line 602) | public TextView getTitleView(int tab) {
method showMsg (line 619) | public void showMsg(int position, int num) {
method showDot (line 644) | public void showDot(int position) {
method hideMsg (line 651) | public void hideMsg(int position) {
method setMsgMargin (line 668) | public void setMsgMargin(int position, float leftPadding, float bottom...
method getMsgView (line 689) | public MsgView getMsgView(int position) {
method setOnTabSelectListener (line 700) | public void setOnTabSelectListener(OnTabSelectListener listener) {
method onSaveInstanceState (line 704) | @Override
method onRestoreInstanceState (line 712) | @Override
class IndicatorPoint (line 725) | class IndicatorPoint {
class PointEvaluator (line 733) | class PointEvaluator implements TypeEvaluator<IndicatorPoint> {
method evaluate (line 734) | @Override
method dp2px (line 745) | protected int dp2px(float dp) {
method sp2px (line 750) | protected int sp2px(float sp) {
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java
class SlidingTabLayout (line 38) | public class SlidingTabLayout extends HorizontalScrollView implements Vi...
method SlidingTabLayout (line 101) | public SlidingTabLayout(Context context) {
method SlidingTabLayout (line 105) | public SlidingTabLayout(Context context, AttributeSet attrs) {
method SlidingTabLayout (line 109) | public SlidingTabLayout(Context context, AttributeSet attrs, int defSt...
method obtainAttributes (line 135) | private void obtainAttributes(Context context, AttributeSet attrs) {
method setViewPager (line 173) | public void setViewPager(ViewPager vp) {
method setViewPager (line 186) | public void setViewPager(ViewPager vp, String[] titles) {
method setViewPager (line 209) | public void setViewPager(ViewPager vp, String[] titles, FragmentActivi...
method notifyDataSetChanged (line 227) | public void notifyDataSetChanged() {
method addNewTab (line 240) | public void addNewTab(String title) {
method addTab (line 254) | private void addTab(final int position, String title, View tabView) {
method updateTabStyles (line 295) | private void updateTabStyles() {
method onPageScrolled (line 317) | @Override
method onPageSelected (line 329) | @Override
method onPageScrollStateChanged (line 334) | @Override
method scrollToCurrentTab (line 339) | private void scrollToCurrentTab() {
method updateTabSelection (line 365) | private void updateTabSelection(int position) {
method calcIndicatorRect (line 382) | private void calcIndicatorRect() {
method onDraw (line 439) | @Override
method setCurrentTab (line 528) | public void setCurrentTab(int currentTab) {
method setCurrentTab (line 534) | public void setCurrentTab(int currentTab, boolean smoothScroll) {
method setIndicatorStyle (line 539) | public void setIndicatorStyle(int indicatorStyle) {
method setTabPadding (line 544) | public void setTabPadding(float tabPadding) {
method setTabSpaceEqual (line 549) | public void setTabSpaceEqual(boolean tabSpaceEqual) {
method setTabWidth (line 554) | public void setTabWidth(float tabWidth) {
method setIndicatorColor (line 559) | public void setIndicatorColor(int indicatorColor) {
method setIndicatorHeight (line 564) | public void setIndicatorHeight(float indicatorHeight) {
method setIndicatorWidth (line 569) | public void setIndicatorWidth(float indicatorWidth) {
method setIndicatorCornerRadius (line 574) | public void setIndicatorCornerRadius(float indicatorCornerRadius) {
method setIndicatorGravity (line 579) | public void setIndicatorGravity(int indicatorGravity) {
method setIndicatorMargin (line 584) | public void setIndicatorMargin(float indicatorMarginLeft, float indica...
method setIndicatorWidthEqualTitle (line 593) | public void setIndicatorWidthEqualTitle(boolean indicatorWidthEqualTit...
method setUnderlineColor (line 598) | public void setUnderlineColor(int underlineColor) {
method setUnderlineHeight (line 603) | public void setUnderlineHeight(float underlineHeight) {
method setUnderlineGravity (line 608) | public void setUnderlineGravity(int underlineGravity) {
method setDividerColor (line 613) | public void setDividerColor(int dividerColor) {
method setDividerWidth (line 618) | public void setDividerWidth(float dividerWidth) {
method setDividerPadding (line 623) | public void setDividerPadding(float dividerPadding) {
method setTextsize (line 628) | public void setTextsize(float textsize) {
method setTextSelectColor (line 633) | public void setTextSelectColor(int textSelectColor) {
method setTextUnselectColor (line 638) | public void setTextUnselectColor(int textUnselectColor) {
method setTextBold (line 643) | public void setTextBold(int textBold) {
method setTextAllCaps (line 648) | public void setTextAllCaps(boolean textAllCaps) {
method setSnapOnTabClick (line 653) | public void setSnapOnTabClick(boolean snapOnTabClick) {
method getTabCount (line 658) | public int getTabCount() {
method getCurrentTab (line 662) | public int getCurrentTab() {
method getIndicatorStyle (line 666) | public int getIndicatorStyle() {
method getTabPadding (line 670) | public float getTabPadding() {
method isTabSpaceEqual (line 674) | public boolean isTabSpaceEqual() {
method getTabWidth (line 678) | public float getTabWidth() {
method getIndicatorColor (line 682) | public int getIndicatorColor() {
method getIndicatorHeight (line 686) | public float getIndicatorHeight() {
method getIndicatorWidth (line 690) | public float getIndicatorWidth() {
method getIndicatorCornerRadius (line 694) | public float getIndicatorCornerRadius() {
method getIndicatorMarginLeft (line 698) | public float getIndicatorMarginLeft() {
method getIndicatorMarginTop (line 702) | public float getIndicatorMarginTop() {
method getIndicatorMarginRight (line 706) | public float getIndicatorMarginRight() {
method getIndicatorMarginBottom (line 710) | public float getIndicatorMarginBottom() {
method getUnderlineColor (line 714) | public int getUnderlineColor() {
method getUnderlineHeight (line 718) | public float getUnderlineHeight() {
method getDividerColor (line 722) | public int getDividerColor() {
method getDividerWidth (line 726) | public float getDividerWidth() {
method getDividerPadding (line 730) | public float getDividerPadding() {
method getTextsize (line 734) | public float getTextsize() {
method getTextSelectColor (line 738) | public int getTextSelectColor() {
method getTextUnselectColor (line 742) | public int getTextUnselectColor() {
method getTextBold (line 746) | public int getTextBold() {
method isTextAllCaps (line 750) | public boolean isTextAllCaps() {
method getTitleView (line 754) | public TextView getTitleView(int tab) {
method showMsg (line 772) | public void showMsg(int position, int num) {
method showDot (line 796) | public void showDot(int position) {
method hideMsg (line 804) | public void hideMsg(int position) {
method setMsgMargin (line 817) | public void setMsgMargin(int position, float leftPadding, float bottom...
method getMsgView (line 836) | public MsgView getMsgView(int position) {
method setOnTabSelectListener (line 847) | public void setOnTabSelectListener(OnTabSelectListener listener) {
class InnerPagerAdapter (line 851) | class InnerPagerAdapter extends FragmentPagerAdapter {
method InnerPagerAdapter (line 855) | public InnerPagerAdapter(FragmentManager fm, ArrayList<Fragment> fra...
method getCount (line 861) | @Override
method getPageTitle (line 866) | @Override
method getItem (line 871) | @Override
method destroyItem (line 876) | @Override
method getItemPosition (line 882) | @Override
method onSaveInstanceState (line 888) | @Override
method onRestoreInstanceState (line 896) | @Override
method dp2px (line 910) | protected int dp2px(float dp) {
method sp2px (line 915) | protected int sp2px(float sp) {
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/listener/CustomTabEntity.java
type CustomTabEntity (line 5) | public interface CustomTabEntity {
method getTabTitle (line 6) | String getTabTitle();
method getTabSelectedIcon (line 8) | @DrawableRes
method getTabUnselectedIcon (line 11) | @DrawableRes
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/listener/OnTabSelectListener.java
type OnTabSelectListener (line 3) | public interface OnTabSelectListener {
method onTabSelect (line 4) | void onTabSelect(int position);
method onTabReselect (line 5) | void onTabReselect(int position);
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/utils/FragmentChangeManager.java
class FragmentChangeManager (line 9) | public class FragmentChangeManager {
method FragmentChangeManager (line 17) | public FragmentChangeManager(FragmentManager fm, int containerViewId, ...
method initFragments (line 25) | private void initFragments() {
method setFragments (line 34) | public void setFragments(int index) {
method getCurrentTab (line 48) | public int getCurrentTab() {
method getCurrentFragment (line 52) | public Fragment getCurrentFragment() {
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/utils/UnreadMsgUtils.java
class UnreadMsgUtils (line 16) | public class UnreadMsgUtils {
method show (line 17) | public static void show(MsgView msgView, int num) {
method setSize (line 49) | public static void setSize(MsgView rtv, int size) {
FILE: FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/widget/MsgView.java
class MsgView (line 15) | public class MsgView extends TextView {
method MsgView (line 25) | public MsgView(Context context) {
method MsgView (line 29) | public MsgView(Context context, AttributeSet attrs) {
method MsgView (line 33) | public MsgView(Context context, AttributeSet attrs, int defStyleAttr) {
method obtainAttributes (line 39) | private void obtainAttributes(Context context, AttributeSet attrs) {
method onMeasure (line 51) | @Override
method onLayout (line 63) | @Override
method setBackgroundColor (line 74) | public void setBackgroundColor(int backgroundColor) {
method setCornerRadius (line 79) | public void setCornerRadius(int cornerRadius) {
method setStrokeWidth (line 84) | public void setStrokeWidth(int strokeWidth) {
method setStrokeColor (line 89) | public void setStrokeColor(int strokeColor) {
method setIsRadiusHalfHeight (line 94) | public void setIsRadiusHalfHeight(boolean isRadiusHalfHeight) {
method setIsWidthHeightEqual (line 99) | public void setIsWidthHeightEqual(boolean isWidthHeightEqual) {
method getBackgroundColor (line 104) | public int getBackgroundColor() {
method getCornerRadius (line 108) | public int getCornerRadius() {
method getStrokeWidth (line 112) | public int getStrokeWidth() {
method getStrokeColor (line 116) | public int getStrokeColor() {
method isRadiusHalfHeight (line 120) | public boolean isRadiusHalfHeight() {
method isWidthHeightEqual (line 124) | public boolean isWidthHeightEqual() {
method dp2px (line 128) | protected int dp2px(float dp) {
method sp2px (line 133) | protected int sp2px(float sp) {
method setDrawable (line 138) | private void setDrawable(GradientDrawable gd, int color, int strokeCol...
method setBgSelector (line 144) | public void setBgSelector() {
FILE: app/src/main/java/com/flyco/tablayoutsamples/adapter/SimpleHomeAdapter.java
class SimpleHomeAdapter (line 14) | public class SimpleHomeAdapter extends BaseAdapter {
method SimpleHomeAdapter (line 19) | public SimpleHomeAdapter(Context context, String[] items) {
method getCount (line 26) | @Override
method getItem (line 31) | @Override
method getItemId (line 36) | @Override
method getView (line 41) | @Override
FILE: app/src/main/java/com/flyco/tablayoutsamples/entity/TabEntity.java
class TabEntity (line 5) | public class TabEntity implements CustomTabEntity {
method TabEntity (line 10) | public TabEntity(String title, int selectedIcon, int unSelectedIcon) {
method getTabTitle (line 16) | @Override
method getTabSelectedIcon (line 21) | @Override
method getTabUnselectedIcon (line 26) | @Override
FILE: app/src/main/java/com/flyco/tablayoutsamples/ui/CommonTabActivity.java
class CommonTabActivity (line 26) | public class CommonTabActivity extends AppCompatActivity {
method onCreate (line 50) | @Override
method tl_2 (line 145) | private void tl_2() {
class MyPagerAdapter (line 182) | private class MyPagerAdapter extends FragmentPagerAdapter {
method MyPagerAdapter (line 183) | public MyPagerAdapter(FragmentManager fm) {
method getCount (line 187) | @Override
method getPageTitle (line 192) | @Override
method getItem (line 197) | @Override
method dp2px (line 203) | protected int dp2px(float dp) {
FILE: app/src/main/java/com/flyco/tablayoutsamples/ui/SegmentTabActivity.java
class SegmentTabActivity (line 21) | public class SegmentTabActivity extends AppCompatActivity {
method onCreate (line 31) | @Override
method tl_3 (line 72) | private void tl_3() {
class MyPagerAdapter (line 107) | private class MyPagerAdapter extends FragmentPagerAdapter {
method MyPagerAdapter (line 108) | public MyPagerAdapter(FragmentManager fm) {
method getCount (line 112) | @Override
method getPageTitle (line 117) | @Override
method getItem (line 122) | @Override
FILE: app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleCardFragment.java
class SimpleCardFragment (line 14) | @SuppressLint("ValidFragment")
method getInstance (line 18) | public static SimpleCardFragment getInstance(String title) {
method onCreate (line 24) | @Override
method onCreateView (line 29) | @Override
FILE: app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleHomeActivity.java
class SimpleHomeActivity (line 15) | public class SimpleHomeActivity extends AppCompatActivity {
method onCreate (line 21) | @Override
FILE: app/src/main/java/com/flyco/tablayoutsamples/ui/SlidingTabActivity.java
class SlidingTabActivity (line 23) | public class SlidingTabActivity extends AppCompatActivity implements OnT...
method onCreate (line 32) | @Override
method onTabSelect (line 111) | @Override
method onTabReselect (line 116) | @Override
class MyPagerAdapter (line 121) | private class MyPagerAdapter extends FragmentPagerAdapter {
method MyPagerAdapter (line 122) | public MyPagerAdapter(FragmentManager fm) {
method getCount (line 126) | @Override
method getPageTitle (line 131) | @Override
method getItem (line 136) | @Override
FILE: app/src/main/java/com/flyco/tablayoutsamples/utils/ViewFindUtils.java
class ViewFindUtils (line 6) | @SuppressWarnings({"unchecked"})
method hold (line 20) | public static <T extends View> T hold(View view, int id) {
method find (line 41) | public static <T extends View> T find(View view, int id) {
Condensed preview — 51 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (198K chars).
[
{
"path": ".gitignore",
"chars": 54,
"preview": ".gradle\n/local.properties\nbuild\n.idea\n*.iml\n.DS_Store\n"
},
{
"path": "CHNAGELOG.md",
"chars": 2800,
"preview": "#Change Log\nVersion 1.1.2 *(2015-10-14)*\n----------------------------\n* add method setViewPager(ViewPager vp, String[] t"
},
{
"path": "FlycoTabLayout_Lib/.gitignore",
"chars": 7,
"preview": "/build\n"
},
{
"path": "FlycoTabLayout_Lib/build.gradle",
"chars": 1236,
"preview": "apply plugin: 'com.android.library'\n\nandroid {\n compileSdkVersion rootProject.ext.compileSdkVersion\n buildToolsVer"
},
{
"path": "FlycoTabLayout_Lib/proguard-rules.pro",
"chars": 666,
"preview": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /U"
},
{
"path": "FlycoTabLayout_Lib/src/main/AndroidManifest.xml",
"chars": 57,
"preview": "<manifest\n package=\"com.flyco.tablayout\">\n</manifest>\n"
},
{
"path": "FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java",
"chars": 35137,
"preview": "package com.flyco.tablayout;\n\nimport android.animation.TypeEvaluator;\nimport android.animation.ValueAnimator;\nimport and"
},
{
"path": "FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SegmentTabLayout.java",
"chars": 26633,
"preview": "package com.flyco.tablayout;\n\nimport android.animation.TypeEvaluator;\nimport android.animation.ValueAnimator;\nimport and"
},
{
"path": "FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java",
"chars": 33598,
"preview": "package com.flyco.tablayout;\n\nimport android.content.Context;\nimport android.content.res.TypedArray;\nimport android.grap"
},
{
"path": "FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/listener/CustomTabEntity.java",
"chars": 240,
"preview": "package com.flyco.tablayout.listener;\n\nimport androidx.annotation.DrawableRes;\n\npublic interface CustomTabEntity {\n S"
},
{
"path": "FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/listener/OnTabSelectListener.java",
"chars": 153,
"preview": "package com.flyco.tablayout.listener;\n\npublic interface OnTabSelectListener {\n void onTabSelect(int position);\n vo"
},
{
"path": "FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/utils/FragmentChangeManager.java",
"chars": 1558,
"preview": "package com.flyco.tablayout.utils;\n\nimport androidx.fragment.app.Fragment;\nimport androidx.fragment.app.FragmentManager;"
},
{
"path": "FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/utils/UnreadMsgUtils.java",
"chars": 1958,
"preview": "package com.flyco.tablayout.utils;\n\n\nimport android.util.DisplayMetrics;\nimport android.view.View;\nimport android.widget"
},
{
"path": "FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/widget/MsgView.java",
"chars": 4930,
"preview": "package com.flyco.tablayout.widget;\n\nimport android.content.Context;\nimport android.content.res.TypedArray;\nimport andro"
},
{
"path": "FlycoTabLayout_Lib/src/main/res/layout/layout_tab.xml",
"chars": 1056,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n "
},
{
"path": "FlycoTabLayout_Lib/src/main/res/layout/layout_tab_bottom.xml",
"chars": 1486,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n "
},
{
"path": "FlycoTabLayout_Lib/src/main/res/layout/layout_tab_left.xml",
"chars": 1487,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n "
},
{
"path": "FlycoTabLayout_Lib/src/main/res/layout/layout_tab_right.xml",
"chars": 1488,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n "
},
{
"path": "FlycoTabLayout_Lib/src/main/res/layout/layout_tab_segment.xml",
"chars": 1326,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n "
},
{
"path": "FlycoTabLayout_Lib/src/main/res/layout/layout_tab_top.xml",
"chars": 1485,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n "
},
{
"path": "FlycoTabLayout_Lib/src/main/res/values/attrs.xml",
"chars": 7984,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <!-- indicator -->\n <!-- 设置显示器颜色 -->\n <attr name=\"tl_indica"
},
{
"path": "LICENSE",
"chars": 1077,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2015 H07000223\n\nPermission is hereby granted, free of charge, to any person obtaini"
},
{
"path": "README.md",
"chars": 4622,
"preview": "# FlycoTabLayout\n["
},
{
"path": "README_CN.md",
"chars": 3755,
"preview": "# FlycoTabLayout\n["
},
{
"path": "app/.gitignore",
"chars": 7,
"preview": "/build\n"
},
{
"path": "app/build.gradle",
"chars": 921,
"preview": "apply plugin: 'com.android.application'\n\nandroid {\n compileSdkVersion rootProject.ext.compileSdkVersion\n buildTool"
},
{
"path": "app/proguard-rules.pro",
"chars": 666,
"preview": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /U"
},
{
"path": "app/src/main/AndroidManifest.xml",
"chars": 1148,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest\n package=\"com.flyco.tablayoutsamples\"\n xmlns:android=\"http://sche"
},
{
"path": "app/src/main/java/com/flyco/tablayoutsamples/adapter/SimpleHomeAdapter.java",
"chars": 1774,
"preview": "package com.flyco.tablayoutsamples.adapter;\r\n\r\nimport android.app.Activity;\r\nimport android.content.Context;\r\nimport and"
},
{
"path": "app/src/main/java/com/flyco/tablayoutsamples/entity/TabEntity.java",
"chars": 692,
"preview": "package com.flyco.tablayoutsamples.entity;\n\nimport com.flyco.tablayout.listener.CustomTabEntity;\n\npublic class TabEntity"
},
{
"path": "app/src/main/java/com/flyco/tablayoutsamples/ui/CommonTabActivity.java",
"chars": 7185,
"preview": "package com.flyco.tablayoutsamples.ui;\n\nimport android.content.Context;\nimport android.graphics.Color;\nimport android.os"
},
{
"path": "app/src/main/java/com/flyco/tablayoutsamples/ui/SegmentTabActivity.java",
"chars": 4080,
"preview": "package com.flyco.tablayoutsamples.ui;\n\nimport android.graphics.Color;\nimport android.os.Bundle;\nimport android.view.Vie"
},
{
"path": "app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleCardFragment.java",
"chars": 1044,
"preview": "package com.flyco.tablayoutsamples.ui;\n\nimport android.annotation.SuppressLint;\nimport android.os.Bundle;\nimport android"
},
{
"path": "app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleHomeActivity.java",
"chars": 1408,
"preview": "package com.flyco.tablayoutsamples.ui;\r\n\r\nimport android.content.Context;\r\nimport android.content.Intent;\r\nimport androi"
},
{
"path": "app/src/main/java/com/flyco/tablayoutsamples/ui/SlidingTabActivity.java",
"chars": 4935,
"preview": "package com.flyco.tablayoutsamples.ui;\n\nimport android.content.Context;\nimport android.graphics.Color;\nimport android.os"
},
{
"path": "app/src/main/java/com/flyco/tablayoutsamples/utils/ViewFindUtils.java",
"chars": 1220,
"preview": "package com.flyco.tablayoutsamples.utils;\r\n\r\nimport android.util.SparseArray;\r\nimport android.view.View;\r\n\r\n@SuppressWar"
},
{
"path": "app/src/main/res/layout/activity_common_tab.xml",
"chars": 4877,
"preview": "<ScrollView\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tl=\"http://schemas.android.com/apk/"
},
{
"path": "app/src/main/res/layout/activity_segment_tab.xml",
"chars": 3671,
"preview": "<ScrollView\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tl=\"http://schemas.android.com/apk/"
},
{
"path": "app/src/main/res/layout/activity_sliding_tab.xml",
"chars": 5272,
"preview": "<ScrollView\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tl=\"http://schemas.android.com/apk/"
},
{
"path": "app/src/main/res/layout/fr_simple_card.xml",
"chars": 496,
"preview": "<RelativeLayout\r\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\r\n android:layout_width=\"match_parent\""
},
{
"path": "app/src/main/res/values/colors.xml",
"chars": 259,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <color name=\"colorPrimary\">#8BC34A</color>\n <color name=\"color"
},
{
"path": "app/src/main/res/values/strings.xml",
"chars": 77,
"preview": "<resources>\n <string name=\"app_name\">FlycoTabLayout</string>\n</resources>\n"
},
{
"path": "app/src/main/res/values/styles.xml",
"chars": 769,
"preview": "<resources>\n\n <!-- Base application theme. -->\n <style name=\"AppTheme\" parent=\"Theme.AppCompat.Light\">\n <!-"
},
{
"path": "build.gradle",
"chars": 575,
"preview": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\napply from: 'depende"
},
{
"path": "dependencies.gradle",
"chars": 1233,
"preview": "ext {\n minSdkVersion = 16\n targetSdkVersion = 29\n compileSdkVersion = 29\n buildToolsVersion = '29.0.2'\n v"
},
{
"path": "gradle/wrapper/gradle-wrapper.properties",
"chars": 232,
"preview": "#Wed Nov 25 18:19:50 CST 2020\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_"
},
{
"path": "gradle.properties",
"chars": 1739,
"preview": "# Project-wide Gradle settings.\n\n# IDE (e.g. Android Studio) users:\n# Gradle settings configured through the IDE *will o"
},
{
"path": "gradlew",
"chars": 5080,
"preview": "#!/usr/bin/env bash\n\n##############################################################################\n##\n## Gradle start "
},
{
"path": "gradlew.bat",
"chars": 2404,
"preview": "@if \"%DEBUG%\" == \"\" @echo off\r\n@rem ##########################################################################\r\n@rem\r\n@r"
},
{
"path": "settings.gradle",
"chars": 38,
"preview": "include ':app', ':FlycoTabLayout_Lib'\n"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the H07000223/FlycoTabLayout GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 51 files (182.2 KB), approximately 46.2k tokens, and a symbol index with 334 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.