title: TabLayout text disappears when visibility goes from GONE to VISIBLE
body: <p>I have a problem with the TabLayout in Android. I'm using AppCompat library because my min SDK is 10. The problem is that if the TabLayout has visibility GONE when the activity is first created, when I set the visibility to VISIBLE later, the tab tittles and tab indicator are missing.</p>
  
  <p>Here is my MainActivity:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }  
  
      /**
       * Called when we press the button.
       */
      public void openTabActivity(View view) {
          Intent intent = new Intent(this, TabActivity.class);
          startActivity(intent);
      }
  }
  </code></pre>
  
  <p>TabActivity is this:</p>
  
  <pre><code>public class TabActivity extends FragmentActivity {
  
      MyPagerAdapter mMyPagerAdapter;
      ViewPager mViewPager;
      TabLayout mTabLayout;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_tab);
  
          // ViewPager and its adapters use support library
          // fragments, so use getSupportFragmentManager.
          mMyPagerAdapter =
                  new MyPagerAdapter(
                          getSupportFragmentManager());
          mViewPager = (ViewPager) findViewById(R.id.myViewPager);
          mViewPager.setAdapter(mMyPagerAdapter);
  
          // Link the TabLayout with the ViewPager.
          mTabLayout = (TabLayout) findViewById(R.id.myTab);
          mTabLayout.setupWithViewPager(mViewPager);
  
          // If I set visibility GONE it doesn't show titles 
          // when I set it to VISIBLE again.
          // If I remove this, it works fine.
          mTabLayout.setVisibility(View.GONE);
  
      }
  
      /**
       * If the tab is visible it turn it gone, if it's gone it turn it
       * visible.
       * @param view
       */
      public void toggleTab(View view) {
          Log.d(this.getClass().toString(), "ShowTab()");
          if (mTabLayout.getVisibility() == View.VISIBLE) {
              Log.d(this.getClass().toString(), "Turning GONE");
              mTabLayout.setVisibility(View.GONE);
          } else {
              Log.d(this.getClass().toString(), "Turning VISIBLE");
              mTabLayout.setVisibility(View.VISIBLE);
          }
      }    
  }
  </code></pre>
  
  <p>Page adapter:</p>
  
  <pre><code>public class MyPagerAdapter extends FragmentStatePagerAdapter {
  
      final int PAGE_COUNT = 3;
      private String tabTitles[] = new String[]{"Tab 1", "Tab 2", "Tab 3"};
  
      public MyPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int i) {
          Fragment fragment = new MyFragment();
          return fragment;
      }
  
      @Override
      public int getCount() {
          return PAGE_COUNT;
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          // Generate title based on item position
          return tabTitles[position];
      }
  }
  </code></pre>
  
  <p>Fragment:</p>
  
  <pre><code>public class MyFragment extends Fragment {
  
      public static MyFragment newInstance() {
          MyFragment fragment = new MyFragment();
          return fragment;
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.my_fragment, container, false);
          return view;
      }
  
  }
  </code></pre>
  
  <p>Layouts are very simple too:</p>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:tools="http://schemas.android.com/tools"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:paddingLeft="@dimen/activity_horizontal_margin"
                  android:paddingRight="@dimen/activity_horizontal_margin"
                  android:paddingTop="@dimen/activity_vertical_margin"
                  android:paddingBottom="@dimen/activity_vertical_margin"
                  tools:context=".MainActivity"&gt;
  
      &lt;Button
          android:layout_width="match_parent"
          android:layout_height="200dp"
          android:onClick="openTabActivity"
          android:textColor="#55F"
          android:text="Press to go to Tabs"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>activity_tab.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                tools:context=".TabActivity"&gt;
  
      &lt;android.support.design.widget.TabLayout
          android:id="@+id/myTab"
          style="@style/AppTheme.Tab.NavigationTab"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@color/lightPrimaryColor"/&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/myViewPager"
          android:layout_width="match_parent"
          android:layout_height="0px"
          android:layout_weight="1"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>my_fragment.xml</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
               xmlns:tools="http://schemas.android.com/tools"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               tools:context=".MyFragment"&gt;
  
      &lt;Button
          android:layout_width="200dp"
          android:layout_height="200dp"
          android:onClick="toggleTab"
          android:text="Press"/&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>If i set visibility GONE in TabActivity.onCreate it fails. If it's VISIBLE in TabActivity.onCreate it works. </p>
  
  <p>I've tried to use .invalidate() but it doesn't work.</p>
  
  <p>Can anybody help me?</p>
  
  <p>Thanks in advance for your help.</p>