如何以编程方式更改操作栏的选定选项卡指示器?我已经阅读了有关选项卡样式和Tab.setCustomView()方法的内容,但这些都没有帮助:
使用选项卡样式,我可以更改指示器颜色,但它将保留所有选项卡(我想为每个选项卡设置一个指示器)。
使用选项卡自定义视图,我使用一个包含
TextView
用于选项卡标题和View
以管理指示器颜色的布局。在Java中,我动态更改View
的背景,但问题是View
的背景与选项卡边界不匹配。
<TextView
android:id="@+id/custom_tab_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:gravity="center|center_horizontal"
android:textStyle="bold"/>
<View
android:id="@+id/custom_tab_view"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentBottom="true"/>
有人能告诉我错在哪里吗?还有其他方法可以做到吗?谢谢
setLeftStripDrawable
和setRightStripDrawable
。 - Lia Proninapadding和margin
设置为0dp
,但没有效果。 - S.Thiongane