Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove TabIndicator from PagerTabStrip in a ViewPager

I have a viewpager that uses a PagerTabStrip to indicate the current page. However, I don't want the default indicator to be present. (Underline underneath the page title)

I've tried a few different methods to remove it, but none of them seem to work.

PagerTabStrip pts = (PagerTabStrip) findViewById(R.id.pager_title_strip); pts.setTabIndicatorColor(getResources().getColor(android.R.color.transparent));

also

PagerTabStrip pts = (PagerTabStrip) findViewById(R.id.pager_title_strip); pts.setTabIndicatorColor(Color.parseColor("#80000000"));

and

PagerTabStrip pts = (PagerTabStrip) findViewById(R.id.pager_title_strip); pts.setTabIndicatorColor(Color.TRANSPARENT);

None of these seems to work. Instead it gives me a black indicator instead. Any help would be appreciated. THanks!

like image 716
android_student Avatar asked Nov 27 '12 19:11

android_student


3 Answers

By looking at the source of PagerTabStrip. I have found the following method:

/**
 * Set whether this tab strip should draw a full-width underline in the
 * current tab indicator color.
 *
 * @param drawFull true to draw a full-width underline, false otherwise
 */
public void setDrawFullUnderline(boolean drawFull) {
    mDrawFullUnderline = drawFull;
    mDrawFullUnderlineSet = true;
    invalidate();
}

I have not tested this, but I suppose this should work. Leave a comment if it doesn't.

like image 52
Tobrun Avatar answered Oct 31 '22 23:10

Tobrun


PagerTitleStrip is what you need. It has the same functionality, just without the underline color.

like image 25
James Goodwin Avatar answered Oct 31 '22 23:10

James Goodwin


If you don't want use PagerTitleStrip, you can set the Indicator Color to same color of Background PagerTabStrip

like image 1
Guihgo Avatar answered Oct 31 '22 23:10

Guihgo