title: Why do the TabLayout's tabs' icons/texts blink when swiping between pages?
body: <h2>Background</h2>
  
  <p>I've used the <a href="https://github.com/astuetz/PagerSlidingTabStrip" rel="nofollow noreferrer"><strong>PagerSlidingTabStrip</strong></a> library for a long time, to show tabs above a ViewPager.</p>
  
  <p>Recently, I was tasked to set icons (using selectors, with selected-vs-unselected states) instead of texts for the tabs, and so I did. However, it seems that the library couldn't handle it well, showing empty tabs sometimes, so I've moved to <a href="https://developer.android.com/reference/android/support/design/widget/TabLayout.html" rel="nofollow noreferrer"><strong>TabLayout</strong></a>, which is a part of the design library by Google</p>
  
  <h2>The problem</h2>
  
  <p>I've noticed a few solutions of how to add icons to the TabLayout, but each of them has one or more of those issues :</p>
  
  <ol>
  <li>no icons are shown</li>
  <li>icons are shown, but can blink from time to time, especially when using a selector for them with "exitFadeDuration" being set, or when swiping fast</li>
  <li>clicking on tabs does not change the current page of the viewPager.</li>
  </ol>
  
  <h2>The code</h2>
  
  <p>The code I've used is from <a href="https://github.com/chrisbanes/cheesesquare" rel="nofollow noreferrer"><strong>cheesesquare</strong></a> sample, in the MainActivity.java file. It's quite basic:</p>
  
  <pre><code>      final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
        ...
        tabLayout.setupWithViewPager(viewPager);
  </code></pre>
  
  <p>The solutions I've tried are:</p>
  
  <ol>
  <li><p>setting an icon for each tab (and remove "getPageTitle" code of the adapter) :</p>
  
  <pre><code>for (int i = 0; i &lt; tabLayout.getTabCount(); i++) 
      tabLayout.getTabAt(i).setIcon(...);
  </code></pre>
  
  <p>Also tried adding setOnTabSelectedListener for when I didn't use a selector.</p>
  
  <p>This solution results in blinking effect (issue #2).</p></li>
  <li><p>Extending TabLayout to support icons or implementing TabViewProvider, as shown <a href="https://stackoverflow.com/a/31090168/878126"><strong>here</strong></a>. </p>
  
  <p>Extending TabLayout doesn't show icons at all (issue #1), and implementing TabViewProvider has the issue of blinking icons (quite rare though).</p></li>
  <li><p>For getPageTitle, return a SpannableString that has the icon in it, as shown <a href="https://stackoverflow.com/a/31109560/878126"><strong>here</strong></a> . This didn't show the icons at all for me. </p></li>
  </ol>
  
  <p>I remember I tried other solutions too, but they also had issues as I've mentioned.</p>
  
  <h2>The question</h2>
  
  <p>What is the correct way to set icons for the tabs?</p>
  
  <p>Is there an official way to achieve this? I'd like to at least have a selected&amp;unselected images for each tab. The transition of when selecting is a good bonus, which I've hoped to achieve as it looks nicer this way.</p>
  
  <p>Why do the icons blink anyway? I've noticed that it occurs even for texts...</p>
  
  <p>Is there maybe a workaround?</p>