效果图:
![](https://img.haomeiwen.com/i1722765/92ee032af0f5e643.png)
indicator.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:gravity="center"
android:width="@dimen/dp_26"
android:height="@dimen/dp_4">
<shape>
<gradient android:angle="0" android:startColor="#7E51FF" android:endColor="#B643D0"/>
</shape>
</item>
</layer-list>
布局如下:
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/sp_10"
app:tabMode="fixed"
app:tabIndicator="@drawable/indicator"
app:tabIndicatorFullWidth="false"
app:tabIndicatorHeight="@dimen/dp_4"
app:tabSelectedTextColor="@color/black"
app:tabTextColor="@color/black" >
<com.google.android.material.tabs.TabItem
android:text="待审核(2)"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<com.google.android.material.tabs.TabItem
android:text="已审核(5)"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<com.google.android.material.tabs.TabItem
android:text="已下架(3)"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</com.google.android.material.tabs.TabLayout>
表示:tabitem撑满
表示:引用自定义指示器
表示:指示器根据宽度根据文字长度来定
表示:指示器的高度
表示:tabitem选中时的字体颜色
表示:tabitem默认状态下的字体颜色
网友评论