原文链接
Android自带TabLayout
在SDK28后可以设置下方下划线更随字体长度变化(再也不需要反射了,也不需要引入第三方控件了)
布局中引用 app:tabIndicatorFullWidth=“false”
<com.google.android.material.tabs.TabLayout
app:tabIndicatorFullWidth="false"
app:tabRippleColor="@null"
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabTextColor="#000000" />
app:tabIndicatorFullWidth=“false” 指示器充满屏幕,设置为false后就会根据字体长度变化。