Github url


by hackware1993

hackware1993 /MagicIndicator

A powerful, customizable and extensible ViewPager indicator framework. As the best alternative of Vi...

7.9K Stars 1.3K Forks Last release: over 1 year ago (1.6.0) 163 Commits 12 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


A powerful, customizable and extensible ViewPager indicator framework. As the best alternative of ViewPagerIndicator, TabLayout and PagerSlidingTabStrip.

Android ArsenalCodewake



Simple steps, you can integrate MagicIndicator:

  1. checkout out MagicIndicator, which contains source code and demo
  2. import module magicindicator and add dependency:
compile project(':magicindicator')


repositories { ... maven { url "" } } dependencies { ... compile 'com.github.hackware1993:MagicIndicator:1.5.0' }
  1. add MagicIndicator to your layout xml:
<?xml version="1.0" encoding="utf-8"?><linearlayout xmlns:android="" xmlns: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"></net.lucode.hackware.magicindicator.magicindicator>

      < android:id="@+id/view_pager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"></>

  1. find MagicIndicator through code, initialize it:
MagicIndicator magicIndicator = (MagicIndicator) findViewById(\_indicator); CommonNavigator commonNavigator = new CommonNavigator(this); commonNavigator.setAdapter(new CommonNavigatorAdapter() { @Override public int getCount() { return mTitleDataList == null ? 0 : mTitleDataList.size(); } @Override public IPagerTitleView getTitleView(Context context, final int index) { ColorTransitionPagerTitleView colorTransitionPagerTitleView = new ColorTransitionPagerTitleView(context); colorTransitionPagerTitleView.setNormalColor(Color.GRAY); colorTransitionPagerTitleView.setSelectedColor(Color.BLACK); colorTransitionPagerTitleView.setText(mTitleDataList.get(index)); colorTransitionPagerTitleView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mViewPager.setCurrentItem(index); } }); return colorTransitionPagerTitleView; } @Override public IPagerIndicator getIndicator(Context context) { LinePagerIndicator indicator = new LinePagerIndicator(context); indicator.setMode(LinePagerIndicator.MODE\_WRAP\_CONTENT); return indicator; } }); magicIndicator.setNavigator(commonNavigator);
  1. work with ViewPager:
ViewPagerHelper.bind(magicIndicator, mViewPager);


work with Fragment Container(switch Fragment by hide()、show()): ```java mFramentContainerHelper = new FragmentContainerHelper(magicIndicator);

// ...

mFragmentContainerHelper.handlePageSelected(pageIndex); // invoke when switch Fragment ```


MagicIndicator can be easily extended:

  1. implement IPagerTitleView to customize tab:
public class MyPagerTitleView extends View implements IPagerTitleView { public MyPagerTitleView(Context context) { super(context); } @Override public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) { } @Override public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) { } @Override public void onSelected(int index, int totalCount) { } @Override public void onDeselected(int index, int totalCount) { } }
  1. implement IPagerIndicator to customize indicator:
public class MyPagerIndicator extends View implements IPagerIndicator { public MyPagerIndicator(Context context) { super(context); } @Override public void onPageSelected(int position) { } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageScrollStateChanged(int state) { } @Override public void onPositionDataProvide(List<positiondata> dataList) {
  1. use CommonPagerTitleView to load custom layout xml.

Now, enjoy yourself!

See extensions in app/src/main/java/net/lucode/hackware/magicindicatordemo/ext,more extensions adding...

Who developed?

[email protected]

[email protected]

Q&A MagicIndicator交流群

An intermittent perfectionist.

Visit My Blog for more articles about MagicIndicator.


MIT License Copyright (c) 2016 hackware1993 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Have seen here, give a star?(都看到这儿了,何不给个...,哎,别走啊,star还没...)

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.