在kotiln中 tablayout 禁止被点击
时间: 2024-05-05 10:19:25 浏览: 43
你可以在 Kotlin 中通过 setOnTabSelectedListener 方法来禁止 TabLayout 被点击。代码如下:
```
tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
// Do something when tab is selected.
}
override fun onTabUnselected(tab: TabLayout.Tab) {
// Do something when tab is unselected.
}
override fun onTabReselected(tab: TabLayout.Tab) {
// Do something when tab is reselected.
}
override fun onTabReselected(tab: TabLayout.Tab) = Unit
override fun onTabUnselected(tab: TabLayout.Tab) {
// Disable the tab so it cannot be clicked.
tab.view.isClickable = false
}
})
```
这段代码会在 Tab 被取消选中时禁用它,使其不能被点击。
阅读全文