1
TabLayoutMediator(
            tabbedFragmentView.tabs,tabbedFragmentView.view_pager)
 { tab, position ->
            tab.text = tabFragmentList[position].title
 }.attach()

I could not find a way to set a subtitle, there is only one set text function available it would be the main title for the tab layout tab what if I want a subtitle too.

Matrix
  • 503
  • 3
  • 17
Jack
  • 1,825
  • 3
  • 26
  • 43

2 Answers2

0

You need to set a custom view for the tab:

TabLayoutMediator(tabbedFragmentView.tabs, tabbedFragmentView.view_pager) { tab, position -> 
    val customTabView = View() // inflate your custom view here
    // set title and subtitle
    tab.setCustomView(customTabView)
}.attach()
sdex
  • 3,169
  • 15
  • 28
0

tabLayout with viewpager2 : you can refer this link

TabLayoutMediator(tabLayout, viewPager) { tab, position ->
tab.text = tabTitles[position]
viewPager.setCurrentItem(tab.position, true)
}.attach()
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108