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
  • 330
  • 1
  • 13
Jack
  • 1,644
  • 2
  • 17
  • 42

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
  • 2,154
  • 12
  • 27
0

tabLayout with viewpager2 : you can refer this link

TabLayoutMediator(tabLayout, viewPager) { tab, position ->
tab.text = tabTitles[position]
viewPager.setCurrentItem(tab.position, true)
}.attach()
shirley
  • 10,698
  • 8
  • 25
  • 48