选项​​卡自定义视图中TabLayout未选择 [英] Tab custom view not selected in TabLayout

查看:488
本文介绍了选项​​卡自定义视图中TabLayout未选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有TabLayout设置有ViewPager和我使用的标签自定义视图。每个自定义视图是包含适当状态的ImageView的(选定,$ P $不同的可绘制pssed等)的简单的FrameLayout。这个问题只发生在开始。未选择第一个选项卡的ImageView的虽然ViewPager目前的产品项目0其他选项卡上攻丝时,问题就消失了,所以它只是一个初始化的问题。它是一个Android的问题?有没有解决办法?我试过无效的观点,但似乎没有任何工作。

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.

推荐答案

使用此code上setupWithViewPager后的onCreate()()方法被调用。

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

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

这篇关于选项​​卡自定义视图中TabLayout未选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆