TabLayout color of selected tab underline

后端 未结 3 1473
轮回少年
轮回少年 2020-12-24 04:54

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), Tab

相关标签:
3条回答
  • 2020-12-24 05:11

    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;
                    }
                });
    
    0 讨论(0)
  • 2020-12-24 05:16

    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.

    0 讨论(0)
  • 2020-12-24 05:23

    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);
         }
    });
    
    0 讨论(0)
提交回复
热议问题