Asked
Active
Viewed 454 times
0

Akshay Katariya
- 1,464
- 9
- 20

Parth Mistry
- 39
- 8
-
set `tabSelectedTextColor` in your tab layout – Vikas singh Jan 29 '18 at 06:38
2 Answers
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);
}
}
);

Akshay Katariya
- 1,464
- 9
- 20
-
I used this code, but on default position = 0 doesn't work. Can you have solution for that? @Akshay – Parth Mistry Feb 20 '18 at 07:28
-
"default position = 0 doesn't work " means it does not work every time or under specific condition like first time it's not working and then it works – Akshay Katariya Feb 20 '18 at 07:39
0
In your xml use style like this
<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"
/>
and in your Style.xml use tabSelectedTextColor
with your value like this .
<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>
and its done .:)

Tejas Pandya
- 3,987
- 1
- 26
- 51