android tablay动态添加tabitem
2020-04-24 本文已影响0人
hao_developer

val tabStr = arrayListOf<String>().apply {
add("美妆个护")
add("水果生鲜")
add("食品饮料")
add("母婴玩具")
add("服饰")
add("美妆")
}
//去掉tablayout点击阴影效果
tabLay.setTabRippleColor(ColorStateList.valueOf(resources.getColor(android.R.color.transparent)))//去掉点击背景
tabLay.removeAllTabs()
tabStr.forEachIndexed { index, value ->
val tab = tabLay.newTab()
tab.setText(value)
tabLay.addTab(tab,index,if(tabIndex == index) true else false)
}