Mostafa Addam Mostafa Addam - 1 month ago 8
Android Question

Tabs Title not showing

I'm facing an issue using the

TabLayout
. I updated the design library to v25.0.0 and now the tab titles are not showing up. Here is my code:

public void setupTabs() {
animateUserProfileOptions();
setupViewPager(viewPager);
}

public void setupViewPager(final ViewPager viewPager) {
TabPagerAdapter adapter = new TabPagerAdapter(getSupportFragmentManager());
Fragment news = new NotificationNews();
Fragment request = new NotificationRequests();

adapter.addFragment(news , getApplicationContext().getString(R.string.notification_news));
adapter.addFragment(request, getApplicationContext().getString(R.string.notification_request));
viewPager.setAdapter(adapter);
tlUserProfileTabs.post(new Runnable() {
@Override
public void run() {
tlUserProfileTabs.setupWithViewPager(viewPager);
}
});
}


Here is my adapter:

public class TabPagerAdapter extends FragmentPagerAdapter {

private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();

public TabPagerAdapter(android.support.v4.app.FragmentManager manager) {
super(manager);
}

@Override
public android.support.v4.app.Fragment getItem(int position) {
return mFragmentList.get(position);
}

@Override
public int getCount() {
return mFragmentList.size();
}

public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}

@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}

}


Here is my xml layout
enter code here



<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/home_primary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<android.support.design.widget.TabLayout
android:id="@+id/tlUserProfileTabs"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#f2f2f2"
app:tabGravity="fill"
app:tabIndicatorColor="#28A9E0"
app:tabTextColor="#999999"
app:tabSelectedTextColor="#28A9E0"
app:tabTextAppearance="@drawable/tab_selector"
app:tabIndicatorHeight="4dp"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />




Am I missing something or what? Any help would be appreciated, thanks.

Answer

Try to remove the tabTextAppearance

app:tabTextAppearance="@drawable/tab_selector"

It might be conflicting with the app selected text color and text color