I'm using the SlidingTabLayout with spannable so as the Title I've got the icons. How can I change the icon color for selected?
Asked
Active
Viewed 1,189 times
0
-
check this: http://stackoverflow.com/a/26934274/4409113 – ʍѳђઽ૯ท Jun 01 '15 at 10:45
-
I've already try this. But this change the text color. It won't change the spannable string color. – Manuel Castro Jun 01 '15 at 10:48
-
Try this: https://github.com/astuetz/PagerSlidingTabStrip/pull/62/files?short_path=04c6e90 – Arj 1411 Jun 01 '15 at 11:24
1 Answers
0
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setOnTabSelectedListener(
new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
@Override
public void onTabSelected(TabLayout.Tab tab) {
super.onTabSelected(tab);
int tabIconColor = ContextCompat.getColor(context, R.color.tabSelectedIconColor);
tab.getIcon().setColorFilter(tabIconColor, PorterDuff.Mode.SRC_IN);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
super.onTabUnselected(tab);
int tabIconColor = ContextCompat.getColor(context, R.color.tabUnselectedIconColor);
tab.getIcon().setColorFilter(tabIconColor, PorterDuff.Mode.SRC_IN);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
super.onTabReselected(tab);
}
}
);

Manfred Radlwimmer
- 13,257
- 13
- 53
- 62