- TabLayout
- MagicIndicator
- ViewPagerIndicator
- TabPageIndicator
- PagerSlidingTabStrip
1. TabLayout
/初始化tab
String[] names = new String[]{"商品", "评价", "商家"};
for (String name : names) {
TabLayout.Tab tab = mHd.tabLayout.newTab().setText(name);
mHd.tabLayout.addTab(tab);
}
//初始化ViewPager,包含三个标题对应的三个Fragment页面
BusinessActivityVpAdapter adapter = new BusinessActivityVpAdapter(getSupportFragmentManager());
mHd.viewpager.setAdapter(adapter);
//绑定指示器与ViewPager,让用户点击标题切换viewpager,切换viewpager可以同步标题
mHd.tabLayout.setupWithViewPager(mHd.viewpager);
2. MagicIndicator
A powerful, customizable and extensible ViewPager indicator framework. As the best alternative of ViewPagerIndicator, TabLayout and PagerSlidingTabStrip —— 强大、可定制、易扩展的 ViewPager 指示器框架。是ViewPagerIndicator、TabLayout、PagerSlidingTabStrip的最佳替代品。支持角标,更支持在非ViewPager场景下使用(使用hide()、show()切换Fragment或使用setVisibility切换FrameLayout里的View等)
GitHub地址:https://github.com/hackware1993/MagicIndicator
3. ViewPagerIndicator
GitHub地址:https://github.com/JakeWharton/ViewPagerIndicator
地址:http://www.jianshu.com/p/a2263ee3e7c3
4. PagerSlidingTabStrip
/**
* 初始化指示器
*
* @param view
*/
private void initIterator(View view) {
pst_bbs_iterator = (PagerSlidingTabStrip) view.findViewById(R.id.pst_bbs_iterator);
//设置指针的外观
pst_bbs_iterator.setTextColorStateListResource(R.drawable.selector_tab_text);
pst_bbs_iterator.setTextSize(DensityUtil.dip2px(getActivity(), 15));
pst_bbs_iterator.setIndicatorColorResource(R.color.themeColor);
pst_bbs_iterator.setIndicatorHeight(3);
pst_bbs_iterator.setBackgroundColor(Color.WHITE);
pst_bbs_iterator.setTabBackground(android.R.color.transparent);
pst_bbs_iterator.setViewPager(vp_bbs);
}