title: Using TabLayout inside a Fragment; tab text invisible
body: <p>I'm currently experimenting with various new components in the new <a href="http://android-developers.blogspot.de/2015/05/android-design-support-library.html">Android Support Design library</a>. I've implemented a <code>NavigationView</code> in my <code>MainActivity.java</code>, which uses a FragmentManager to navigate between the items in the Navigation drawer:</p>
  
  <pre><code>getSupportFragmentManager()
      .beginTransaction()
      .replace(R.id.content, mTabLayoutFragment)
      .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
      .commit();
  </code></pre>
  
  <p>I'm using a <code>TabLayout</code> in one of the fragments. Here is the fragment's layout:</p>
  
  <pre><code>&lt;android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;android.support.design.widget.TabLayout
          android:id="@+id/tabLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          app:tabMode="fixed"
          app:tabGravity="fill"
          app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/viewpager"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@android:color/white"/&gt;
  
  &lt;/android.support.design.widget.AppBarLayout&gt;
  </code></pre>
  
  <p>And the Java code behind it:</p>
  
  <pre><code>import android.os.Bundle;
  import android.support.design.widget.*;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentStatePagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class TabLayoutFragment extends Fragment {   
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View inflatedView = inflater.inflate(R.layout.fragment_tablayout, container, false);
  
          TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tabLayout);
          tabLayout.addTab(tabLayout.newTab().setText("Campusplan"));
          tabLayout.addTab(tabLayout.newTab().setText("Raumplan"));
          final ViewPager viewPager = (ViewPager) inflatedView.findViewById(R.id.viewpager);
  
          viewPager.setAdapter(new PagerAdapter
                  (getFragmentManager(), tabLayout.getTabCount()));
          viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
          tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
              @Override
              public void onTabSelected(TabLayout.Tab tab) {
                  viewPager.setCurrentItem(tab.getPosition());
              }
  
              @Override
              public void onTabUnselected(TabLayout.Tab tab) {
  
              }
  
              @Override
              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;
          }
  
          @Override
          public Fragment getItem(int position) {
  
              switch (position) {
                  case 0:
                      TabItem1 tab1 = new TabItem1();
                      return tab1;
                  case 1:
                      TabItem1 tab2 = new TabItem1();
                      return tab2;
                  default:
                      return null;
              }
          }
  
          @Override
          public int getCount() {
              return mNumOfTabs;
          }
      }
  }
  </code></pre>
  
  <p>Please note <code>TabItem1</code> and <code>TabItem1</code>, which are fragments consisting of nothing but a TextView. These two are to be displayed in the TabLayout.</p>
  
  <p>Now, this code seems to be working, to some extent. Here is how it looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/9WkIN.png"><img src="https://i.stack.imgur.com/9WkIN.png" alt=""></a></p>
  
  <p>What's weird is, after I <strong>rotate</strong> the device, everything seems to be working just fine:</p>
  
  <p><a href="https://i.stack.imgur.com/vp8Fu.png"><img src="https://i.stack.imgur.com/vp8Fu.png" alt="enter image description here"></a></p>
  
  <p>It seems like something gets called upon a configuration change. This is weird, especially considering that I have following in my <code>AndroidManifest</code>: </p>
  
  <pre><code>android:configChanges="orientation|screenSize"
  </code></pre>