implementation 'com.yayaG.colorTrackTabLayout:colortracklayout:1.0.0'
maven { url 'https://dl.bintray.com/wangjinya/maven' }
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://dl.bintray.com/wangjinya/maven' }
}
}
ColorTrackFragmentAdapter
ColorTrackAdapter
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity">
<com.jackwang.colortracklayout.ColorTrackLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
app:tabMode="scrollable"
/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
public class MyAdapter extends ColorTrackFragmentAdapter {
private List<String> titles = new ArrayList<>();
.....
@Nullable
@Override
public List<String> getTitles() {
return titles;
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return titles.get(position);
}
}
MyAdapter adapter = new MyAdapter(getSupportFragmentManager(), this);
mViewPager.setAdapter(adapter);
//默认颜色和字体滑动颜色
mTabLayout.setNormalColorAndSelectedColor(Color.BLACK, Color.GREEN);
//字体大小
mTabLayout.setTabLayoutTextSize(18);
mTabLayout.setupWithViewPager(mViewPager, adapter);