0

I need to change the background color of the selected tab when the user click on it to white.

Those two attempts are not working (the first is commented)

tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
//                LinearLayout parent = new LinearLayout(getApplicationContext());
//                parent.setLayoutParams(new LinearLayout.LayoutParams(LinearLayoutCompat.LayoutParams.MATCH_PARENT, LinearLayoutCompat.LayoutParams.WRAP_CONTENT));
//                parent.setBackgroundColor(getResources().getColor(R.color.white));
//                tab.setCustomView(parent);
                tabLayout.getTabAt(tabLayout.getSelectedTabPosition()).setBackgroundColor(getResources().getColor(R.color.white));
            }

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

            }

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

            }
        });
Cœur
  • 37,241
  • 25
  • 195
  • 267
TSR
  • 17,242
  • 27
  • 93
  • 197
  • 1
    [here](http://stackoverflow.com/a/32082705/4554623) it is already answered... have you tried it ? or you are trying something else ... – sodhankit Mar 01 '17 at 13:36
  • 1
    Please stop repeating the same question. Simply editing your original post with any new information you have, any new code you've tried, or an explanation of why any posted answers aren't working will bump it to the top of the active queue. – Mike M. Mar 01 '17 at 17:54

0 Answers0