TabLayout color of selected tab underline

AndroidAndroid Layout

Android Problem Overview


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.

enter image description here

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

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);
     }
});

Solution 3 - Android

you can use setcustomTebColorizer below is the example

mSlidingTabLayout=(SlidingTabLayout)findViewById(R.id.sliding_tabs);
        mSlidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
            @Override
            public int getIndicatorColor(int position) {
                return Color.YELLOW;
            }

                @Override
                public int getDividerColor(int position) {
                    return 0;
                }
            });

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfweiglView Question on Stackoverflow
Solution 1 - AndroidJared BurrowsView Answer on Stackoverflow
Solution 2 - AndroidHaresh ChhelanaView Answer on Stackoverflow
Solution 3 - AndroidSAMView Answer on Stackoverflow