Im setting the tablayout as follows,
private void setupTabIcons() {
TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabOne.setText("Status");
tabOne.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.status, 0, 0);
tabLayout.getTabAt(0).setCustomView(tabOne);
TextView tabTwo = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabTwo.setText("Rating");
tabTwo.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.rateit, 0, 0);
tabLayout.getTabAt(1).setCustomView(tabTwo);
}
How can I be able to change the icon of selected tab? im using tablayout.
I am using TabLayout.OnTabSelectedListener
:
wptabs.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
tab.setIcon(R.drawable.newicon);
//also you can use tab.setCustomView() too
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
tab.setIcon(R.drawable.oldicon);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.