You have to use this TabLayoutMediator
that mimics tabLayout.setupWithViewPager()
and sets up the ViewPager2
with Tablayout
. Otherwise, you will have to write your own adapter that will combine both parties.
Its code will look like this in Kotlin
TabLayoutMediator(tabLayout, viewPager) { tab, position ->
tab.text = tabTitles[position]
}.attach()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…