我一直在寻找如何将Tablayout中的指示器更改为圆形,如下所示

但我不知道该怎么做,帮帮忙!
发布于 2016-03-17 21:24:26
在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"/>所以我相信你不能把它变成一个可画的形状,你只能改变它的颜色。
另一种方法是为选项卡定义自定义视图,然后自己处理指示器状态
发布于 2016-03-17 21:20:09
1)创建选项卡状态的布局(例如: tab_selected.xml和tab_unselected.xml)
2)使用您的布局为选项卡设置自定义视图:
//get your tab item
TabLayout.Tab tabItem = tabLayout.getTabAt(i);
//inflate your layout to a view and set it as the tab's custom view
tabItem.setCustomView(customView);3)然后,使用setOnTabSelectedListener,保持监听哪个选项卡被选中,并相应地更新其自定义视图(使用setCustomView
发布于 2016-03-17 21:23:42
我认为你应该使用标签的自定义视图,并用你的TabLayout.OnTabSelectedListener来改变它
https://stackoverflow.com/questions/36060196
复制相似问题