Can't remove PagerTabStrip tab indicator bar - Android

I would like to remove the PagerTabStrip tab indicator, but I cannot find a way. I tried to set setDrawFullUnderline (false) but it still exists. If I set my color to transparent, I get a black line: - /

How could I get rid of him? Thank!

PagerTabStrip pagerTabStrip = (PagerTabStrip) findViewById (R.id.pager_tab_strip); pagerTabStrip.setDrawFullUnderline (true); pagerTabStrip.setTabIndicatorColor (Color.TRANSPARENT);

<android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="390dp"
        android:layout_above="@+id/page_indicator"
        android:padding="20dp">

        <android.support.v4.view.PagerTabStrip
            android:id="@+id/pager_tab_strip"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:background="@android:color/transparent"
            android:textAppearance="@style/PagerTabStripText"
            android:paddingTop="5dp"
            android:paddingBottom="5dp" />

        </android.support.v4.view.ViewPager>

      

enter image description here

+3


source to share


2 answers


    tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    tabs.setIndicatorHeight(0);

      



Set the height of the zero indicator. Hope this helps.

0


source


Yes, documents for

setTabIndicatorColor()

      

say:

The high byte (alpha) is ignored.

sets its own alpha on the tab strip based on the position of how you slide the page.



So let's get angry and stomp all over this!

public class PagerTabStripNoInd extends PagerTabStrip {
    private static final String TAG = "PagerTabStripNoInd";
    private static final Integer ZERO = new Integer(0);
    public PagerTabStripNoInd(Context context) {
        super(context);
    }
    public PagerTabStripNoInd(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    @Override
    protected void onDraw(Canvas canvas) {
        try {
            Field tabAlphaField = PagerTabStrip.class.getField("mTabAlpha");
            tabAlphaField.setAccessible(true);
            tabAlphaField.set(this, ZERO);
        } catch (NoSuchFieldException e) {
            Log.e(TAG, "onDraw", e);
        } catch (IllegalAccessException e) {
            Log.e(TAG, "onDraw", e);
        }
        super.onDraw(canvas);
    }
}

      

Since position-dependent alpha is computed by another method, if we set it to zero before we draw, the tab color becomes truly transparent.

Use it like this:

<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="fill_parent"
    android:layout_height="390dp"
    android:layout_above="@+id/page_indicator"
    android:padding="20dp">

    <!-- use your fully qualified class name here, for example -->
    <com.example.PagerTabStripNoInd
        android:id="@+id/pager_tab_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="@android:color/transparent"
        android:textAppearance="@style/PagerTabStripText"
        android:paddingTop="5dp"
        android:paddingBottom="5dp" />

</android.support.v4.view.ViewPager>

      

-1


source







All Articles