FlycoTabLayout 是一个一个安卓的Tablayout库,其中主要包含了CommonTabLayout,SegmenTabLayout,SlidingTabLayout。相信到这里就会有很多人问这是一个什么鬼,不说那么多直接上图,简单粗暴。
implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
CommonTabLayout的用法:
1.布局
<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"/>
<android.support.v4.view.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>
2.业务:
public class CommonTabActivity extends AppCompatActivity {
private Context mContext = this;
private ArrayList<Fragment> mFragments = new ArrayList<>();
private ArrayList<Fragment> mFragments2 = new ArrayList<>();
/*文本信息*/
private String[] mTitles = {"首页", "消息", "联系人", "更多"};
/*未选择时的icon*/
private int[] mIconUnselectIds = {
R.mipmap.tab_home_unselect, R.mipmap.tab_speech_unselect,
R.mipmap.tab_contact_unselect, R.mipmap.tab_more_unselect};
/*选择时的icon*/
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 */
mTabLay