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

34,874

Solution 1

This just works.

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

Thanks!

Solution 2

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

Solution 3

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" />
Share:
34,874

Related videos on Youtube

intrepidkarthi
Author by

intrepidkarthi

I am Karthikeyan NG, working as a software programmer in Bangalore,India. Exploring new technologies, Bike riding, PC Gaming, Reading Novels, Blogging are my hobbies.

Updated on March 15, 2020

Comments

  • intrepidkarthi
    intrepidkarthi over 4 years

    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. But I don't know whether it is a color by default or not. And also I have one more doubt. If I use PagerTitleStrip this tab highlighter doesn't appear. Is there a way to bring that with titlestrip?

    Here is my layout:

      <android.support.v4.view.PagerTabStrip android:id="@+id/pager_title_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="@color/pager_titlestrip_bg"    
        android:textColor="@color/pager_titlestrip_text"
        android:paddingTop="5dp"
        android:paddingBottom="4dp" >   
      </android.support.v4.view.PagerTabStrip>
    
    • intrepidkarthi
      intrepidkarthi almost 12 years
      I have looked into JakeWharton ViewPager Indicator solution. For me the tabs along with swipe just works fine. But I want to change the tab indicator color. There is option to change the tab textcolor. But not the indicator color. It is showing as black by default.
  • TheRealChx101
    TheRealChx101 almost 5 years
    How about XML only?