android TabLayout changing color of selected tab icon showing dim white color

3.7k Views Asked by At

I have used tab layout with image of android design library. When changing color of selected tab icon white,white color is not showing perfectly but it shows dim white color. How to show prefect white color on selected tab?

slidingTabLayout.getTabAt(0).setIcon(R.drawable.ic_tab_recent);
slidingTabLayout.getTabAt(1).setIcon(R.drawable.ic_tab_profile);
slidingTabLayout.getTabAt(2).setIcon(R.drawable.ic_tab_contacts);
slidingTabLayout.getTabAt(3).setIcon(R.drawable.ic_tab_settings);

slidingTabLayout.getTabAt(0).getIcon().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
slidingTabLayout.getTabAt(1).getIcon().setColorFilter(Color.parseColor("#a8a8a8"), PorterDuff.Mode.SRC_IN);
slidingTabLayout.getTabAt(2).getIcon().setColorFilter(Color.parseColor("#a8a8a8"), PorterDuff.Mode.SRC_IN);
slidingTabLayout.getTabAt(3).getIcon().setColorFilter(Color.parseColor("#a8a8a8"), PorterDuff.Mode.SRC_IN);


slidingTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        tab.getIcon().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);

    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {
        tab.getIcon().setColorFilter(Color.parseColor("#a8a8a8"), PorterDuff.Mode.SRC_IN);
    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }
});
1

There are 1 best solutions below

1
On BEST ANSWER

I checked by changing all colors(Color.WHITE,Color.BLUE) and drawable.It didn't worked for me. Later on , I checked the drawable used it was of color brown .After changing color of drawable white it worked for me.

It was drawing in the brown drawable due to PorterDuff.Mode.SRC_IN. For more information about PorterDuff.Mode