Tablayout
引入
compile 'com.android.support:design:25.1.0'
XML
<android.support.design.widget.TabLayout
app:tabSelectedTextColor=""//选中时文字颜色
app:tabTextColor=""//默认文字颜色
app:tabIndicatorColor=""//选中时指示器颜色
app:tabIndicatorHeight="4dp"//高度为0 相当于无指示器
app:tabBackground=""//背景色
app:tabTextAppearance="@android:style/TextAppearance.Holo.Large"//设置文字的style
app:tabMode="scrollable"//tablayout 可滑动,如果tab多的话,默认fixed:固定宽
app:tabGravity="center"//
app:tabMaxWidth="dp"
使用
mTabLayout.addTab(mTabLayout.newTab().setText(""));//添加空tab
mTabLayout.addTab(mTabLayout.newTab().setText("").setIcon());//添加空tab
viewPager.setAdapter(new FragmentTabAdapter(getSupportFragmentManager(),
mAppTabs));
**mTabLayout.setupWithViewPager(viewPager);//与ViewPager 联动**
mTabLayout.getTabAt(position).select();//默认选中项
或者 直接设置viewPager 的选中项
viewPager.setCurrentItem(mTabIndex);
ViewPager
FragmentPagerAdapter
getPageTitle
getCount
getItem
getSupportFragmentManager()