未选中的标签下划线的TabLayout颜色 [英] TabLayout color of unselected tab underline

查看:483
本文介绍了未选中的标签下划线的TabLayout颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此图片的标签布局中,选定的标签栏下划线颜色为紫色,并带有文本.

In this picture, in tablayout, selected tabbar underline color is purple, and text.

我搜索了未选中的标签栏,但是找不到未选中的标签栏下划线.

I search of unselected tabbar, but I couldn't find unselected tabbar underline.

我要在选择某些标签时更改颜色,更改未选择的标签栏下划线颜色.

I want change the color when I select some tab, change the unselected tabbar underline color.

如果您知道这一点,您能帮我吗?

If you know about this, would you help me?

推荐答案

在可绘制文件夹中创建xml文件

Create an xml file inside your drawable folder

custom_indicator.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" />

要更改未选择的标签文本颜色,只需提供默认的标签文本颜色和选定的标签文本颜色,如下所示:

To change the unselected tab text color, simple provide a default tab text color and selected tab text color as follows:

<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" />

这篇关于未选中的标签下划线的TabLayout颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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