I\'m using the SlidingTabLayout from google (https://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html).
It wo
I had a similar problem but I was using a custom page title View with an icon and a text. To set custom colors when a tab is selected/unselected, I used the selector created by @PanayiotisIrakleous, so a big thanks to him for posting it.
Here's how I did it:-
1- Create a xml file for the selector. I made a file, slidingtab_title_color.xml
and placed it in Drawable
folder.
2- Open your custom layout for tab title and add the selector
file in the android:textColor
attribute. My custom file is named as slidingtab_title_color.xml
and has the following code-
3- (Optional) If you want to change the color of the indicator and the background of sliding tab then add the following line to the file where you are initializing your SlidingTabLayout
-
mSlidingTab.setBackgroundColor(getResources().getColor(R.color.primaryColor));
mSlidingTab.setSelectedIndicatorColors(getResources().getColor(R.color.accentColor));
Just make sure that you are adding these lines before you are setting the ViewPager
for the SlidingTabLayout
.
And that's it, here's how it will look.
For those who still have problems, here's the bitbucket link for the project source and this link for the all the projects on Material design.