How to make the icons in TabLayout change depending on whether the tab is active or not?

    1 answer 1

    tabLayout.setOnTabSelectedListener( new TabLayout.ViewPagerOnTabSelectedListener(viewPager) { @Override public void onTabSelected(TabLayout.Tab tab) { super.onTabSelected(tab); tab.getIcon().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN); } @Override public void onTabUnselected(TabLayout.Tab tab) { super.onTabUnselected(tab); tab.getIcon().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN); } @Override public void onTabReselected(TabLayout.Tab tab) { super.onTabReselected(tab); } } ); 

    onTabSelected - performed when clicking on an inactive tab

    onTabUnselected - performed when switching to another tab

    onTabReselected - performed when you click the tab again