注:(1)degsin包與v7包需一致油吭,例如我在編譯版本為23 ?在gradle文件中引入包如下
?????? (2)要使用design主題:且任何屬性都不能為null
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/red_ba0019</item>
</style>
在布局文件中:
其中tabIndicatorHeight屬性代表tabLayout下劃線的高度 ?為0dp不顯示下劃線 ?tabIndictorColor是下劃線的顏色 ?tabSelectedTextColor是選中tab的顏色 ? tabTextColor是未選中tab的顏色
FragmentStatePagerAdapter的實(shí)現(xiàn)類:
mFragments是對應(yīng)Tab切換時(shí)所展現(xiàn)的Fragment,mTitles是TabLayout的標(biāo)簽顯示內(nèi)容
在主Activity中(BaseActivity中抽象方法 initData() 在initView()之前 ):
最后顯示(圖中列表是在第一個(gè)Fragment中寫的):