如何更改选定的选项卡标题颜色

How to change selected tab title color

我需要在我的选项卡 activity 中更改 选定的选项卡颜色

例如,选中的项目文本颜色必须是 #cea939,未选中的项目颜色必须是 #d7ba60。我应该怎么做才能改变它?实际上,我尝试将 textColor 值添加到 apptheme_tab_indicator.xml - 但没有结果。对了,我用的是AppCompat。如果有解决方案,stylesstyles-v21 有何不同?

你可以查看我对post的回答,对标签使用自定义视图,并将背景颜色设置代码更改为文本颜色设置代码:

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

希望对您有所帮助!