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

intrepidkarthi picture intrepidkarthi · Sep 13, 2012 · Viewed 34.2k times · Source

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>

Answer

intrepidkarthi picture intrepidkarthi · Sep 14, 2012

This just works.

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

Thanks!