0
我正在使用SlidingTabLayout spannable所以標題我有圖標。如何更改所選圖標顏色?SlidingTabLayout更改顏色選擇圖標
我正在使用SlidingTabLayout spannable所以標題我有圖標。如何更改所選圖標顏色?SlidingTabLayout更改顏色選擇圖標
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);
}
}
);
檢查此:http://stackoverflow.com/a/26934274/4409113 – Mohsen
我已經試過這個。但是這改變了文字顏色。它不會更改可跨越的字符串顏色。 –
試試這個: https://github.com/astuetz/PagerSlidingTabStrip/pull/62/files?short_path=04c6e90 –