Via XML attributes:
<android.support.design.widget.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:tabMode="fixed" app:tabGravity="fill" app:tabTextColor="@color/your_unselected_text_color" app:tabSelectedTextColor="@color/your_selected_text_color"/>
In addition, for further styling, there are attributes such as tabIndicatorColor or tabIndicatorHeight.
In code:
tabLayout.setTabTextColors( getResources().getColor(R.color.your_unselected_text_color), getResources().getColor(R.color.your_selected_text_color) );
Since this old method is deprecated as API 23, an alternative:
tabLayout.setTabTextColors( ContextCompat.getColor(context, R.color.your_unselected_text_color), ContextCompat.getColor(context, R.color.your_selected_text_color) );
Fe Le Aug 30 '15 at 12:06 2015-08-30 12:06
source share