How can I change the color of the underline of the selected tab on the new TabLayout? The PagerTabStrip has a method setTabIndicatorColor(int color)
, TabLayout
doesn't seem to have such a method.
Right-click the worksheet tab whose color you want to change. Choose Tab Color, and then select the color you want. The color of the tab changes, but not the color of the font.
In Android TabLayout is a new element introduced in Design Support library. It provides horizontal layout to display tabs on the screen. We can display more screens in a single screen using tabs. We can quickly swipe between the tabs.
These methods have a features: always attaching the "tab widget" with a ViewPager , and in order to make this requirement, we must disable swipe feature of the ViewPager . Now, with Material design, we now use TabLayout widget, which can "stand alone" to build a tab bar and do not need a ViewPager anymore.
Use app:tabIndicatorColor
.
Example:
<android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabIndicatorColor="@android:color/white" />
Make sure you have this namespace
: xmlns:app="http://schemas.android.com/apk/res-auto"
Documentation: https://developer.android.com/reference/android/support/design/widget/TabLayout.html#attr_android.support.design:tabIndicatorColor.
Try to download below file from this location :
https://github.com/google/iosched/tree/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget
SlidingTabLayout.java SlidingTabStrip.java
Try to set tab indicator color this way :
slidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() { @Override public int getIndicatorColor(int position) { return getResources().getColor(R.color.color_name); } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With