【android】TabLayout文字闪烁问题
安卓MD设计提供了一个非常酷炫的效果,TabLayout拿来做选项卡时非常合适的,但是在实际使用中发现22.2.1版本号的TabLayout在ViewPager滑动的时候会出现闪烁现象。
解决方法:在gradle文件里
1:要么升级到23.x(compile 'com.android.support:design:23.1.1')
2:要么使用22.0里最后一个没有bug的版本(compile 'com.android.support:design:22.2.0')
以上只是针对tabLayout文字闪烁的情况,如果图片闪烁要么升级到23.x
要么请参考以下方式自行解决,来源http://stackoverflow.com/questions/31828610/why-do-the-tablayouts-tabs-icons-texts-blink-when-swiping-between-pages
use the old version (22.2.0) as I've mentioned above.
you need to avoid using selectors for the icons. Use the exact image resource ids instead:
private static final int[] TAB_ICONS_UNSELECTED = {... }; private static final int[] TAB_ICONS_SELECTED = {... };
update the icons based on the page selections, as such:
mViewPager.addOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(final int position) { for (int i = 0; i < tabLayout.getTabCount(); ++i) tabLayout.getTabAt(i).setIcon(i != position ? TAB_ICONS_UNSELECTED[i] : TAB_ICONS_SELECTED[i]); } });
Also, remember to call about the same loop when initializing the TabLayout. Something like that:
for (int i = 0; i < tabLayout.getTabCount(); ++i) tabLayout.getTabAt(i).setIcon(i != mViewPager.getCurrentItem() ? TAB_ICONS_UNSELECTED[i] : TAB_ICONS_SELECTED[i]);
I think that this should also fix the issue for texts and not just icons.