如何改变新TabLayout指示灯的颜色,高度 [英] How to change the new TabLayout indicator color and height

查看:688
本文介绍了如何改变新TabLayout指示灯的颜色,高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩弄新的 android.support.design.widget.TabLayout ,并发现了一个问题,在类的定义,有没有方法改变指示灯的颜色和默认的高度。

I was playing around with the new android.support.design.widget.TabLayout, and found a problem, in the class definition, there are no methods to change the indicator color, and default height.

做一些研究,发现默认的指示灯颜色取自AppTheme。特别是从这里开始:

Doing some research, found that the default indicator color is taken from the AppTheme. Specifically from here:

<item name="colorAccent">#FF4081</item>

现在,在我的情况,如果我改变了 colorAccent ,就会影响到所有其他视图,它使用这个值作为背景色,例如进度

Now, in my case, if I change the colorAccent, it will affect all the other views which uses this value as background color, for example ProgressBar

现在有没有什么办法的indicatorColor更改为另一件事除了 colorAccent

Now is there any way to change the indicatorColor to other thing besides the colorAccent?

推荐答案

有了新TabLayout使用指示灯的颜色从值 colorAccent 的问题,我决定挖到 android.support.design.widget.TabLayout 执行,发现没有任何公开的方法来进行定义。但是我发现TabLayout的这种风格说明:

Having the problem that the new TabLayout uses the indicator color from the value colorAccent, I decided to dig into the android.support.design.widget.TabLayout implementation, finding that there are no public methods to customize this. However I found this style specification of the TabLayout:

<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
    <item name="tabMaxWidth">@dimen/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>

有这种风格的规范,现在我们可以自定义TabLayout是这样的:

Having this style specification, now we can customize the TabLayout like this:

<android.support.design.widget.TabLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@id/pages_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:tabIndicatorColor="@android:color/white"
    app:tabIndicatorHeight="4dp"/>

和问题解决了,这两个选项卡指示灯的颜色,高度可以从改变其缺省值。

And problem solved, both the tab indicator color and height can be changed from their default values.

这篇关于如何改变新TabLayout指示灯的颜色,高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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