I am using the SlidingTabLayout
class to display tabs in my Android application.
I'm using my custom tab view which I set with the setCustomTabView
function. Although I can easily customize the selected tab text color, I can not find a way to customize the text color of the unselected tab. In the L preview documentation they suggest that it should be #fff
60%, and I want to use that exact same value also. I looked at the SlidingTabLayout
and SlidingTabStrip
classes, but could not figure out where should I make modifications.
The answer turned out to be quite simple, actually.. I don't know why I did not think of it sooner..
For everybody who wonder, you should simply create tab_text.xml
in the res/colors folder, with content:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/selected" android:state_selected="true" />
<item android:color="@android:color/unselected" />
</selector>
And then set the defined xml (tab_text.xml
) to the textColor
attribute of the custom tab view (in my case the custom view is a simple TextView
).
Sandra's approach didn't work for me, because setSelected()
is not called for specific view. My solution here.
来源:https://stackoverflow.com/questions/25568392/custom-unselected-tab-text-color-in-slidingtablayout