1) First of all create color folder under res (/res/color)
2) create xml file selector.xml under /res/color folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@android:color/white" />
<item android:state_focused="true" android:color="@android:color/white" />
<item android:state_pressed="true" android:color="@android:color/white" />
<item android:color="#504f4f" />
</selector>
3) Then in the populateTabStrip() method in SlidingTabLayout put this
tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));
now you have a selector and you can change the color of the text on any event you want
if that is not working add the following lines of code.
a) in populateTabStrip() method at the end add this
if (i == mViewPager.getCurrentItem()) {
tabView.setSelected(true);
}
and b) change the onPageSelected() method to this
@Override
public void onPageSelected(int position) {
if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
mTabStrip.onViewPagerPageChanged(position, 0f);
scrollToTab(position, 0);
}
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
mTabStrip.getChildAt(i).setSelected(position == i);
}
if (mViewPagerPageChangeListener != null) {
mViewPagerPageChangeListener.onPageSelected(position);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…