Android 表格布局指示器自定义
我一直在研究如何将TableLayout中的指示器更改为圆形,如下所示 但我不知道怎么做,有什么帮助吗 1)为选项卡状态创建布局(例如:tab_selected.xml和tab_unselected.xml) 2) 使用布局为选项卡设置自定义视图:Android 表格布局指示器自定义,android,android-tablayout,Android,Android Tablayout,我一直在研究如何将TableLayout中的指示器更改为圆形,如下所示 但我不知道怎么做,有什么帮助吗 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 c
//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) 然后,使用,继续收听选择的选项卡,并相应地更新其自定义视图(使用)我认为您应该使用选项卡的自定义视图,并将其与表格布局一起更改。从中,选项卡指示器定义为:
<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>
<declare-styleable name="TabLayout">
<attr name="tabIndicatorColor" format="color"/>
<attr name="tabIndicatorHeight" format="dimension"/>
@尺寸/设计选项卡最大宽度
?属性/颜色重音
2dp
12dp
12dp
?属性/可选择项背景
@样式/文本外观.Design.Tab
?android:textColorPrimary
属性定义为:
<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>
<declare-styleable name="TabLayout">
<attr name="tabIndicatorColor" format="color"/>
<attr name="tabIndicatorHeight" format="dimension"/>
所以我相信你不能把它改成可画的形状,你只能改变它的颜色
另一种方法是为选项卡定义自定义视图并自己处理指示器状态这会提供动画吗?@user1278890如果你的意思是像从选定状态到未选定状态的动画一样,我不这么认为。