MagicIndicator


Source link: https://github.com/hackware1993/MagicIndicator

MagicIndicator

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

Usage

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')

or

repositories {

  ...
  maven {

url "https://jitpack.io"
  
}
 
}
  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="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>
  1. find MagicIndicator through code, initialize it:
MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_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);

or

work with Fragment Container(switch Fragment by hide()?show()):

mFramentContainerHelper = new FragmentContainerHelper(magicIndicator);
  // ...  mFragmentContainerHelper.handlePageSelected(pageIndex);

// invoke when switch Fragment

Extend

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

An intermittent perfectionist.

Visit My Blog for more articles about MagicIndicator.

License

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. 

More

Have seen here, give a star?????????????...???????star??...?

Resources

A KV store base on sqlite for Android Application.

Fragment Creator is a code generation library to manage fragment class creation and arguments for Android.

A Loading View for Android.

The indirect-injector simplify confusion of communication between activity and fragment, and dependencies.

This project allows to add decoration element at the corner of view.

Android Utility classes.

  • Simple logging
  • AppCompatPreferenceActivity
  • Functional Interfaces

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes