Skip to content

AndroidViewPagerIndicator

Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability of content.

Usage

Include one of the widgets in your view. This should usually be placed adjacent to the ViewPager it represents.

<com.viewpagerindicator.TitlePageIndicator
    android:id="@+id/titles"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" />

In your onCreate method (or onCreateView for a fragment), bind the indicator to the ViewPager.

 //Set the pager with an adapter
 ViewPager pager = (ViewPager)findViewById(R.id.pager);
 pager.setAdapter(new TestAdapter(getSupportFragmentManager()));

 //Bind the title indicator to the adapter
 TitlePageIndicator titleIndicator = (TitlePageIndicator)findViewById(R.id.titles);
 titleIndicator.setViewPager(pager);

(Optional) If you use an OnPageChangeListener with your view pager you should set it in the indicator rather than on the pager directly.

 //continued from above
 titleIndicator.setOnPageChangeListener(mPageChangeListener);

vpiCirclePageIndicatorStyle Style Setting

아래와 같은 경고 메세지가 출력될 경우가 있다.

Failed to find style 'vpiCirclePageIndicatorStyle' in current theme

이럴 경우 아래와 같이 vpiTabPageIndicatorStyle를 설정해야 한다.

<?xml version="1.0" encoding="utf-8"?>
<resources>
        <style name="AppTheme" parent="@style/Theme.Sherlock.Light">
                <item name="vpiTabPageIndicatorStyle">@style/TabStyle</item>
        </style>

        <style name="TabStyle" parent="Widget.TabPageIndicator">
                <item name="android:textColor">#FF33AA33</item>
                <item name="android:textSize">14sp</item>
                <item name="android:textStyle">italic</item>
                <item name="android:paddingLeft">16dp</item>
                <item name="android:paddingRight">16dp</item>
                <item name="android:fadingEdge">horizontal</item>
                <item name="android:fadingEdgeLength">8dp</item>
        </style>
</resources>

See also

Favorite site