TabLayout(Android设计库)文本颜色 [英] TabLayout (Android Design Library) Text Color

查看:210
本文介绍了TabLayout(Android设计库)文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android Design库中的新TabLayout.我设法使用 tabLayout.setTabTextColors(colorstatelist)

I'm using the new TabLayout from the Android Design library. I managed to set the textcolor statelist using tabLayout.setTabTextColors(colorstatelist)

如何使用styles.xml实现相同的目的?

How can i achieve the same using styles.xml?

推荐答案

通过XML属性:

<android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:tabTextColor="@color/your_unselected_text_color"
        app:tabSelectedTextColor="@color/your_selected_text_color"/>

此外,还有诸如tabIndicatorColor或tabIndicatorHeight之类的属性可用于进一步的样式设置.

Additionally, there are attributes like tabIndicatorColor or tabIndicatorHeight for further styling.

tabLayout.setTabTextColors(
    getResources().getColor(R.color.your_unselected_text_color),
    getResources().getColor(R.color.your_selected_text_color)
);

由于自API 23起已弃用这种旧方法,因此替代方法是:

Since this old way is deprecated as of API 23, the alternative is:

tabLayout.setTabTextColors(
    ContextCompat.getColor(context, R.color.your_unselected_text_color),
    ContextCompat.getColor(context, R.color.your_selected_text_color)
);

这篇关于TabLayout(Android设计库)文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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