Skip to content Skip to sidebar Skip to footer

Changing The Icon Of Selected Tab

Im setting the tablayout as follows, private void setupTabIcons() { TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); tab

Solution 1:

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) {

        }
    });

Post a Comment for "Changing The Icon Of Selected Tab"