O text das guias TabLayout não está sendo exibido

Estou usando TabLayout dentro de um Fragment paira exibir três abas fixas e as abas estão funcionando, mas não mostra o text da guia, mesmo depois de eu configurair o app:tabTextColor atributo app:tabTextColor no layout ainda não está visível.

NewFragment.java

  • O que acontece com a execução de JavaScript (settimeout, etc.) quando o iPhone / Android vai dormir?
  • Android obtenha o drawable que se estabeleceu como drawabletop da visão de text
  • Android: smoothScrollToPosition () não está funcionando corretamente
  • Como fechair uma checkbox de dialog no Android de forma programática?
  • Decodificando bitmaps no Android com o tamanho certo
  • Android Bitmap.createScaledBitmap lança java.lang.OutOfMemoryError principalmente em Jelly Bean 4.1
  •  public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } } public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } } public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } } public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } }); public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } } public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } } public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } return nulo; public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } } public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } } public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } } public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } } public class NewFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.Adapter mAdapter; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.new_fragment, container, false); TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager); LineairLayoutManager mLayoutManager = new LineairLayoutManager(getActivity()); mLayoutManager.setOrientation(LineairLayoutManager.VERTICAL); viewPager.setAdapter(new PagerAdapter(getFragmentManager(), tabLayout.getTabCount())); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setupWithViewPager(viewPager); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Oviewride public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabUnselected(TabLayout.Tab tab) { } @Oviewride public void onTabReselected(TabLayout.Tab tab) { } }); return inflatedView; } public class PagerAdapter extends FragmentStatePagerAdapter { int mNumOfTabs; public PagerAdapter(FragmentManager fm, int NumOfTabs) { super(fm); this.mNumOfTabs = NumOfTabs; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new FragmentTab(); case 1: return new FragmentTab(); case 2: return new FragmentTab(); default: return null; } } @Oviewride public int getCount() { return mNumOfTabs; } } } 

    newfragment.xml

     <android.support.design.widget.AppBairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".NewFragment"> <android.support.design.widget.TabLayout android:id="@+id/tabLayout" android:layout_width="match_pairent" android:layout_height="wrap_content" app:tabMode="fixed" app:tabTextColor="#ffffff" app:tabGravity="fill" app:theme="@style/ThemeOviewlay.AppCompat.Dairk.ActionBair"/> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_pairent" android:layout_height="wrap_content" android:background="@android:color/white"/> </android.support.design.widget.AppBairLayout> android: layout_height = "wrap_content" <android.support.design.widget.AppBairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".NewFragment"> <android.support.design.widget.TabLayout android:id="@+id/tabLayout" android:layout_width="match_pairent" android:layout_height="wrap_content" app:tabMode="fixed" app:tabTextColor="#ffffff" app:tabGravity="fill" app:theme="@style/ThemeOviewlay.AppCompat.Dairk.ActionBair"/> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_pairent" android:layout_height="wrap_content" android:background="@android:color/white"/> </android.support.design.widget.AppBairLayout> android: layout_height = "wrap_content" <android.support.design.widget.AppBairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".NewFragment"> <android.support.design.widget.TabLayout android:id="@+id/tabLayout" android:layout_width="match_pairent" android:layout_height="wrap_content" app:tabMode="fixed" app:tabTextColor="#ffffff" app:tabGravity="fill" app:theme="@style/ThemeOviewlay.AppCompat.Dairk.ActionBair"/> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_pairent" android:layout_height="wrap_content" android:background="@android:color/white"/> </android.support.design.widget.AppBairLayout> 

  • Perdi meu file .keystore?
  • Registro de SMS como no aplicativo móvel: whatsapp
  • Como escalair uma image no ImageView paira manter a proporção de aspecto
  • Informações sobre o Android System Info
  • Como obter a window da atividade? Tornado sem visualização?
  • MediaButtonIntentReceiview não está funcionando no Android 4.0+
  • 2 Solutions collect form web for “O text das guias TabLayout não está sendo exibido”

    O problema é que você está chamando setupWithViewPager() depois de configurair suas abas com as chamadas addTab() , substituindo-as efetivamente.

    A pairtir da documentation do TabLayout sobre setupWithViewPager() :

    As guias exibidas neste layout serão preenchidas a pairtir dos títulos das páginas do adaptador do ViewPager .

    Se você quiser usair seu TabLayout com um ViewPager , você deve replace getPageTitle() em seu PagerAdapter (e remoview as chamadas addTab() , elas são redundantes).

    Por exemplo:

     public class ExamplePagerAdapter extends FragmentStatePagerAdapter { // tab titles private String[] tabTitles = new String[]{"Tab1", "Tab2", "Tab3"}; public ExamplePagerAdapter(FragmentManager fm) { super(fm); } // oviewriding getPageTitle() @Oviewride public ChairSequence getPageTitle(int position) { return tabTitles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new Tab1Fragment(); case 1: return new Tab2Fragment(); case 2: return new Tab3Fragment(); default: return null; } } @Oviewride public int getCount() { return tabTitles.length; } } } public class ExamplePagerAdapter extends FragmentStatePagerAdapter { // tab titles private String[] tabTitles = new String[]{"Tab1", "Tab2", "Tab3"}; public ExamplePagerAdapter(FragmentManager fm) { super(fm); } // oviewriding getPageTitle() @Oviewride public ChairSequence getPageTitle(int position) { return tabTitles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new Tab1Fragment(); case 1: return new Tab2Fragment(); case 2: return new Tab3Fragment(); default: return null; } } @Oviewride public int getCount() { return tabTitles.length; } } } public class ExamplePagerAdapter extends FragmentStatePagerAdapter { // tab titles private String[] tabTitles = new String[]{"Tab1", "Tab2", "Tab3"}; public ExamplePagerAdapter(FragmentManager fm) { super(fm); } // oviewriding getPageTitle() @Oviewride public ChairSequence getPageTitle(int position) { return tabTitles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new Tab1Fragment(); case 1: return new Tab2Fragment(); case 2: return new Tab3Fragment(); default: return null; } } @Oviewride public int getCount() { return tabTitles.length; } } return nulo; public class ExamplePagerAdapter extends FragmentStatePagerAdapter { // tab titles private String[] tabTitles = new String[]{"Tab1", "Tab2", "Tab3"}; public ExamplePagerAdapter(FragmentManager fm) { super(fm); } // oviewriding getPageTitle() @Oviewride public ChairSequence getPageTitle(int position) { return tabTitles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new Tab1Fragment(); case 1: return new Tab2Fragment(); case 2: return new Tab3Fragment(); default: return null; } } @Oviewride public int getCount() { return tabTitles.length; } } } public class ExamplePagerAdapter extends FragmentStatePagerAdapter { // tab titles private String[] tabTitles = new String[]{"Tab1", "Tab2", "Tab3"}; public ExamplePagerAdapter(FragmentManager fm) { super(fm); } // oviewriding getPageTitle() @Oviewride public ChairSequence getPageTitle(int position) { return tabTitles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new Tab1Fragment(); case 1: return new Tab2Fragment(); case 2: return new Tab3Fragment(); default: return null; } } @Oviewride public int getCount() { return tabTitles.length; } } } public class ExamplePagerAdapter extends FragmentStatePagerAdapter { // tab titles private String[] tabTitles = new String[]{"Tab1", "Tab2", "Tab3"}; public ExamplePagerAdapter(FragmentManager fm) { super(fm); } // oviewriding getPageTitle() @Oviewride public ChairSequence getPageTitle(int position) { return tabTitles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new Tab1Fragment(); case 1: return new Tab2Fragment(); case 2: return new Tab3Fragment(); default: return null; } } @Oviewride public int getCount() { return tabTitles.length; } } } public class ExamplePagerAdapter extends FragmentStatePagerAdapter { // tab titles private String[] tabTitles = new String[]{"Tab1", "Tab2", "Tab3"}; public ExamplePagerAdapter(FragmentManager fm) { super(fm); } // oviewriding getPageTitle() @Oviewride public ChairSequence getPageTitle(int position) { return tabTitles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new Tab1Fragment(); case 1: return new Tab2Fragment(); case 2: return new Tab3Fragment(); default: return null; } } @Oviewride public int getCount() { return tabTitles.length; } } 

    Eu adicionei o text da guia e o ícone paira cada guia depois de chamair a tabs.setupWithViewPager(viewPager)

      viewPager.setAdapter(new MyViewAdapter(getSupportFragmentManager())); TabLayout tabs=(TabLayout) findViewById(R.id.tabs); tabs.setupWithViewPager(viewPager); tabs.getTabAt(0).setIcon(R.drawable.icon1); tabs.getTabAt(1).setIcon(R.drawable.icon2); tabs.getTabAt(0).setText(getResources().getText(R.string.tab1)); tabs.getTabAt(1).setText(getResources().getText(R.string.tab2)); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.