0
在这张照片中,tablayout,选定的TabBar下划线的颜色是紫色,和文本。
我搜索未选中的tabbar,但找不到未选中的tabbar下划线。
我想在选择某个标签时更改颜色,更改未选中的标签栏下划线颜色。
如果你了解这一点,你会帮助我吗?
在这张照片中,tablayout,选定的TabBar下划线的颜色是紫色,和文本。
我搜索未选中的tabbar,但找不到未选中的tabbar下划线。
我想在选择某个标签时更改颜色,更改未选中的标签栏下划线颜色。
如果你了解这一点,你会帮助我吗?
您绘制文件夹内创建一个XML文件
custom_indicator.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- UNSELECTED TAB STATE -->
<item android:state_selected="false" android:state_pressed="false">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Bottom indicator color for the UNSELECTED tab state -->
<item android:top="-5dp" android:left="-5dp" android:right="-5dp">
<shape android:shape="rectangle">
<stroke android:color="#65acee" android:width="2dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
而在你tabLayout
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabBackground="@drawable/custom_indicator" />
要改变未选择的选项卡文本设置该绘制颜色,简单提供默认标签文字颜色并选择标签文本颜色如下:
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabTextColor="@color/unselected_color"
app:tabSelectedTextColor="@color/selected_color"
app:tabBackground="@drawable/custom_indicator" />
谢谢但在这种情况下,未选中的下划线颜色是变化,但选定的颜色不变。 –
请参阅我的编辑 –
我认为我在custom_indicator中创建了一个项目,并将其更改为state_selected ='true',但它不会发生。你的编辑是正确的。谢谢 –