1

If have a TabLayout setup with a ViewPager and I use custom views for the tabs. Each custom view is a simple FrameLayout containing an ImageView with the appropriate states (different drawables for selected, pressed etc). The issue only happens at the beginning. The ImageView of the first tab is not selected although the ViewPager's current item is item 0. The problem disappears when tapping on the other tabs, so it's just an initialization issue. Is it an android issue? Is there a workaround? I tried invalidating the View but nothing seems to work.

Katerina A.
  • 1,268
  • 10
  • 24

1 Answers1

1

Use this code on onCreate() after setupWithViewPager() method is called.

mTabLayout.getTabAt(1).select();    
mTabLayout.getTabAt(0).select();
Myat Min Soe
  • 787
  • 8
  • 32
  • this helps me solve my problem! Thanks. But it's kinda weird why you have to select other index –  Nov 19 '15 at 06:16