Integrate MagicIndicator with ViewPager
mainTo use MagicIndicator with a ViewPager, follow these steps:
- Add to Layout XML: Include the
net.lucode.hackware.magicindicator.MagicIndicatorview and aViewPagerin your layout. - Initialize Navigator: In your Activity/Fragment, create a
CommonNavigatorand set aCommonNavigatorAdapter. The adapter requires you to implementgetCount(),getTitleView(), andgetIndicator(). - Bind to ViewPager: Use
ViewPagerHelper.bind(magicIndicator, mViewPager)to link the indicator to your ViewPager.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="net.lucode.hackware.magicindicatordemo.MainActivity">
<net.lucode.hackware.magicindicator.MagicIndicator
android:id="@+id/magic_indicator"
android:layout_width="match_parent"
android:layout_height="40dp" />
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>