Custom unselected tab text color in SlidingTabLayout

泪湿孤枕 提交于 2019-12-21 20:27:08

问题


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 setCustomTabViewfunction. 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.


回答1:


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).




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!