直接 上代碼
build.gradle 引用
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
佈局文件
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/my_attend_lecture_tablayout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#fff"
app:tl_indicator_color="@color/tab_tv_selected"
app:tl_indicator_corner_radius="1.5dp"
app:tl_textSelectColor="@color/tab_tv_selected"
app:tl_underline_color="@color/tab_tv_selected"
app:tl_indicator_height="3dp"
app:tl_textUnselectColor="@color/light_grey_color"
app:tl_indicator_width="10dp"/>
.java 文件
mAdapter = new MyPagerAdapter(getSupportFragmentManager());
bindingView.myAttendLectureViewpager.setAdapter(mAdapter);
bindingView.myAttendLectureTablayout.setViewPager(bindingView.myAttendLectureViewpager, Constants.MY_ORDER_TITLE_STATUS);
bindingView.myAttendLectureViewpager.setCurrentItem(4);
注意: bindingView.myAttendLectureTablayout xml 佈局文件的控件, bindingView.myAttendLectureViewpager 前臺viewpager ,Constants.MY_ORDER_TITLE_STATUS 靜態數組 如
public static final String MY_ORDER_TITLE_STATUS[]={"全部","待付款","已完成"};
適配器
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 Constants.MY_ORDER_TITLE_STATUS[position];
}
@Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
}
借鑑 :github 地址 https://github.com/H07000223/FlycoTabLayout/issues?q=is%3Aissue+is%3Aopen+tl_indicator_width