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

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

问题描述

我正在使用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 ?

推荐答案

如果使用的是设计支持库,请将此代码添加到您的 tab活动中.

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更改选定的选项卡文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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