如何更改所选标签标题颜色所选、如何更改、颜色、标签

2023-09-12 23:42:07 作者:你侵入我心

我需要改变的选中的标签颜色在我的选项卡活动。

I need to change selected tab color in my tab activity.

例如,所选项目的文本颜色必须是#cea939 ,和未选定项目的颜色必须是#d7ba60 。我应该怎么做才能改变这种状况?其实,我试图文字颜色值添加到 apptheme_tab_indicator.xml - 但没有结果。顺便说一句,我用 AppCompat 。如果有一个解决方案,它是如何发生变化的风格风格-V21

For example, selected item text color must be #cea939, and unselected items colors have to be #d7ba60. What should I do to change that? Actually, I tried to add textColor value to apptheme_tab_indicator.xml - but no result. By the way, I use AppCompat. And if there is a solution, how does it vary for styles and styles-v21?

推荐答案

您可以检查我的答案后How动态地改变Viewpager标签颜色,使用自定义视图选项卡,和恰克的背景颜色设置codeS文字颜色设置​​:

You can check my answer for the post How to change Viewpager tab colour dynamically?, use custom view for tabs, and chage the codes of background color setting to text color setting:

Tab selectedTab = yourActionBar.getSelectedTab();
View tabView = selectedTab.getCustomView();
TextView text = (TextView)tabView.findViewById(R.id.your_text_id);  
text.setColor(your_text_color);

希望这有助于!

Hope this help!