TabLayout Indicator自定义 [英] TabLayout Indicator customization

查看:339
本文介绍了TabLayout Indicator自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索如何将Tablayout中的指示器更改为圆形,像这样

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

但是我不知道该怎么做,有什么帮助!

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

推荐答案

来自

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>

tabIndicatorColor 属性定义为:

<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

这篇关于TabLayout Indicator自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆