TabLayout
- 注意这里添加tab,使用binding.tabLayout.newTab()进行创建
private fun initTabs() {
val tab = binding.tabLayout.newTab()
tab.text = "模板库"
binding.tabLayout.addTab(tab)
binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
}
override fun onTabReselected(tab: TabLayout.Tab?) {
}
})
}
- Android TabLayout+ViewPager2的简单用法(两个Android自带的控件)