最佳答案
来自source code ,标签指示器定义为:
<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
<item name="tabMaxWidth">@dimen/design_tab_max_width</item>
<item name="tabIndicatorColor">?attr/colorAccent</item>
<item name="tabIndicatorHeight">2dp</item>
<item name="tabPaddingStart">12dp</item>
<item name="tabPaddingEnd">12dp</item>
<item name="tabBackground">?attr/selectableItemBackground</item>
<item name="tabTextAppearance">@style/TextAppearance.Design.Tab</item>
<item name="tabSelectedTextColor">?android:textColorPrimary</item>
</style>
和 tabIndicatorColor属性定义为:
<declare-styleable name="TabLayout">
<attr name="tabIndicatorColor" format="color"/>
<attr name="tabIndicatorHeight" format="dimension"/>
所以我相信你不能把它改成可绘制的(形状),你只能改变它的颜色。
另一种方法是为选项卡定义自定义 View 并自己处理指示器状态
关于android - TabLayout Indicator 自定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36060196/