//无效果
vpMain.setCurrentItem(ENTRANCE.Function);
tlMain.getTabAt(0).select();
//有效果
for (int i = 0; i < mainItems.size(); i++) {
View view = LayoutInflater.from(this).inflate(R.layout.view_main_tab, null);
ImageView ivIcon = (ImageView) view.findViewById(R.id.iv_icon);
TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
ivIcon.setBackgroundResource(mainItems.get(i).icon);
tvTitle.setText(mainItems.get(i).title);
tlMain.removeTabAt(i);
if (i == 0){
tlMain.addTab(new TabLayout(this).newTab().setCustomView(view), 0, true);
} else {
tlMain.addTab(new TabLayout(this).newTab().setCustomView(view), i, false);
}
}ViewPager + TabLayout组合默认选择第一项的问题
最新推荐文章于 2022-03-31 19:41:29 发布
本文介绍了一种使用TabLayout动态更新标签的方法。通过for循环遍历并设置每个标签的内容和样式,实现了TabLayout中标签的动态添加和移除。
2506

被折叠的 条评论
为什么被折叠?



