如何使用 Android 代码中的 TabLayout 更改选定的 Tab 文本颜色? [英] How to change selected Tab Text color using TabLayout from code in Android?

查看:50
本文介绍了如何使用 Android 代码中的 TabLayout 更改选定的 Tab 文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 android.support.widget.TabLayout 来创建 Tab 视图,并且我想从代码(不是从 xml 或通过样式)更改选定的标签文本颜色.我该怎么做?

I'm using android.support.widget.TabLayout to make a Tab view, and I want to change the selected tabs text color from code (not from xml or by styling). How can I do this ?

推荐答案

如果您正在使用设计支持库,请将此代码添加到您的标签活动.

If you are using the design support library add this code to your tab activity.

tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FF0000"));
tabLayout.setSelectedTabIndicatorHeight((int) (5 * getResources().getDisplayMetrics().density));
tabLayout.setTabTextColors(Color.parseColor("#727272"), Color.parseColor("#ffffff"));

这将设置标签活动中的标签文本颜色以及标签指示器颜色.

This will set the tab text color as well as tab indicator color in your tab activity.

这篇关于如何使用 Android 代码中的 TabLayout 更改选定的 Tab 文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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