androidandroid-tabsandroid-tablayout

How to change selected Tab Text color using TabLayout from code in Android?


enter image description here

I'm using android.support.widget.TabLayout to make a Tab view, and I want to change the selected tabs text color from code (not from xml or by styling). How can I do this ?


Solution

  • If you are using the design support library add this code to your tab activity.

    tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FF0000"));
    tabLayout.setSelectedTabIndicatorHeight((int) (5 * getResources().getDisplayMetrics().density));
    tabLayout.setTabTextColors(Color.parseColor("#727272"), Color.parseColor("#ffffff"));
    

    This will set the tab text color as well as tab indicator color in your tab activity.