How to change the current tab highlighter color in Android ViewPager?

后端 未结 3 989
Happy的楠姐
Happy的楠姐 2021-02-03 23:36

Here is my layout inside ViewPager. I would like to change the color of the current tab highlighter which is below the text. Actually it is showing in black color.

相关标签:
3条回答
  • 2021-02-04 00:10

    This just works.

    PagerTabStrip pagerTabStrip = (PagerTabStrip) findViewById(R.id.pager_title_strip);
    pagerTabStrip.setDrawFullUnderline(true);
    pagerTabStrip.setTabIndicatorColor(Color.RED);
    

    Thanks!

    0 讨论(0)
  • 2021-02-04 00:19

    This works in my project.

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFF"
        app:tabGravity="fill"
        app:tabIndicatorColor="@color/text3"
        app:tabMode="scrollable"
        app:tabSelectedTextColor="@color/text3"
        app:tabTextColor="#000" />
    
    0 讨论(0)
  • 2021-02-04 00:21

    It can be done in both programmatically with jAVA or with XML

    By XML

    <android.support.design.widget.TabLayout
            android:id="@+id/tabanim_tabs"
            android:layout_width="match_parent"
            app:tabIndicatorHeight="4dp"
            app:tabIndicatorColor="@android:color/white"
            android:layout_height="wrap_content" />
    

    Or more simply you can solve this Code aswell

    tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FFFFFF"));
    

    Similarly to change the Height

    tabLayout.setSelectedTabIndicatorHeight((int) (2 * getResources().getDisplayMetrics().density));
    
    0 讨论(0)
提交回复
热议问题