可以交叉tab和文字的SlidingTab,支持设置渐变色。
implementation 'com.vivian.widgets:slidingtab:1.0.4'
<com.vivian.slidingtab.SlidingTab
android:id="@+id/sliding_tab"
android:layout_width="match_parent"
android:layout_margin="10dp"
app:strokeWidth="2dp"
app:mainColor="#1A51AD"
app:mainColorRes="@color/colorAccent"
app:radius="100dp"
app:tabHeight="100dp"
app:textSize="16sp"
app:startColor="#a1aa0b"
app:endColor="#1F8F70"
android:layout_gravity="center"
android:layout_height="wrap_content"/>
app:strokeWidth="2dp" //设置外围线框宽度
app:mainColor="#1A51AD" //设置主色
app:mainColorRes="@color/colorAccent" //设置主色资源。如果mainColor和mainColorRes同时设置了,按mainColorRes内容显示
app:radius="100dp" //设置圆角尺寸
app:tabHeight="100dp" //设置tab高度
app:textSize="16sp" //设置字体大小
app:startColor="#a1aa0b" //设置渐变色起始颜色
app:endColor="#1F8F70" //设置渐变色结束颜色
slidingTab.setTitles("课程", "文档");
或者
slidingTab.setTitles(List<String> titles)
slidingTab.bindViewPager(viewPager);
slidingTab.setOnTabClickListener(new SlidingTab.OnTabClickListener() {
@Override
public void onTabClick(int position) {
viewPager.setCurrentItem(position);
}
});
Copyright 2019 Vivian
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.