答案 0 :(得分:0)
tabLayout.setOnTabSelectedListener(
new TabLayout.ViewPagerOnTabSelectedListener(viewPager)
{
@Override
public void onTabSelected(TabLayout.Tab tab)
{
super.onTabSelected(tab);
//Set your color here
int tabIconColor = ContextCompat.getColor(context, R.color.colorActive);
tab.getIcon().setColorFilter(tabIconColor, PorterDuff.Mode.SRC_IN);
}
@Override
public void onTabUnselected(TabLayout.Tab tab)
{
super.onTabUnselected(tab);
//Set your color here
int tabIconColor = ContextCompat.getColor(context, R.color.colorInactive);
tab.getIcon().setColorFilter(tabIconColor, PorterDuff.Mode.SRC_IN);
}
@Override
public void onTabReselected(TabLayout.Tab tab)
{
super.onTabReselected(tab);
}
}
);
答案 1 :(得分:0)
在你的xml使用风格中
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
style="@style/AppTabLayout"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?attr/colorPrimary"
/>
并在你的Style.xml中使用tabSelectedTextColor
,你的价值就像这样。
<style name="AppTabLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorHeight">0dp</item>
<item name="tabPaddingStart">0dp</item>
<item name="tabPaddingEnd">0dp</item>
<item name="tabBackground">?attr/selectableItemBackground</item>
<item name="tabTextAppearance">@style/AppTabTextAppearance</item>
<item name="tabSelectedTextColor">#ffffff</item> //your color
<item name="tabGravity">fill</item>
<item name="tabMode">fixed</item>
</style>
及其完成。:)