简体   繁体   中英

Tab custom view not selected in TabLayout

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.

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

mTabLayout.getTabAt(1).select();    
mTabLayout.getTabAt(0).select();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM