I am trying to change the color of the icon in my tabs of tabLayout when tabs are switched. I am using setCustomView(view)
for setting the icons like this.
View view = inflater.inflate(R.layout.layout_icon, null);
view.findViewById(R.id.icon).setBackgroundResource(R.drawable.apple);
TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setCustomView(view));
When a tab is selected I want to change its icon's color, but I don't know how to do it. If I simply setCustomView(view)
on the tab again inside onTabSelected
two icons appear in the tab with different colors, that is the original customView is not removed. How do I remove the custom view? Or what is the way to achieve this? Can someone please help. Thanks in advance !!