*Buenas, tengo un problemita nada grave pero por algún motivo no se ven los títulos de mis tabs. En mi diseño, se pueden ver los nombres:
Y este es el código:
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/negro"
android:theme="@style/AppTheme.AppBarOverlay">
<TextView
android:id="@+id/title"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="@dimen/appbar_padding"
android:text="Book Search"
android:textColor="@color/blanco"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/negro">
<com.google.android.material.tabs.TabItem
android:id="@+id/tabLibro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="uno"/>
<com.google.android.material.tabs.TabItem
android:id="@+id/tabAnime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dos"/>
<com.google.android.material.tabs.TabItem
android:id="@+id/tabVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tres"/>
</com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>
Y este es el código de mi MainActivity
:
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.view_pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabs = findViewById(R.id.tabs);
tabs.setupWithViewPager(mViewPager);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabs));
tabs.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
}
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public PlaceholderFragment() { }
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
return rootView;
}
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch(position) {
case 0:
LibrosFragment lf = new LibrosFragment();
return lf;
case 1:
AnimeFragment af = new AnimeFragment();
return af;
case 2:
YoutubeFragment yf = new YoutubeFragment();
return yf;
default:
return null;
}
}
@Override
public int getCount() {
return 3;
}
}
Así se ve: