1. 程式人生 > >TabLayout+ViewPager 標題不顯示問題

TabLayout+ViewPager 標題不顯示問題

華為 seq cat color 小米手機 def 小米 顯示空白 白色

第一次用TabLayout+ViewPager 組合在布局中寫好了三個標題預覽沒問題而且也設置了

app:tabIndicatorColor="@color/colorAccent" 
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="@color/button_nav_font_default"
三個屬性都設置,當運行在手機上的時候顯示空白剛開始以為是手機問題(華為)換了小米手機也是同樣的問題,我開始懷疑主題問題了,因為我的主題顏色是全是白色以下代碼
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/white</item>
<item name="colorPrimaryDark">@color/white</item>
<item name="colorAccent">@color/white</item>
</style>
我把三種顏色全部改了紅色運行結果是一樣的,
無奈只能搜索了 找到一位博友寫的 http://www.cnblogs.com/neillee/p/7001976.html
設置
mViewPager.setAdapter(new FragmentPagerAdapter(getActivity().getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}

@Override
public int getCount() {
return fragments.size();
}
@Override
public CharSequence getPageTitle(int position) {

return mTabList.get(position);
}
});
紅色關鍵代碼設置vewpage的title字體
運行測試成功

TabLayout+ViewPager 標題不顯示問題