Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabLayout Indicator customization

i have been searching how to change the indicator in Tablayout to be circular, like this enter image description here

but i don't know how to do so, any help!

like image 695
Sarah Avatar asked Oct 30 '22 07:10

Sarah


1 Answers

From the source code, the tab indicator is defined as:

<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>

and the tabIndicatorColor attribute is defined as:

<declare-styleable name="TabLayout">
        <attr name="tabIndicatorColor" format="color"/>
        <attr name="tabIndicatorHeight" format="dimension"/>

so I believe you can't change it to a drawable (shape), you can only change its color.

An alternative is to define a custom view for the tabs and handle the indicator state yourself

like image 156
Mina Wissa Avatar answered Nov 09 '22 16:11

Mina Wissa