【问题标题】:Is there a way to set a title and subtitle for com.google.android.material.tabs.TabLayout Tab?有没有办法为 com.google.android.material.tabs.TabLayout Tab 设置标题和副标题?
【发布时间】:2021-06-09 04:38:03
【问题描述】:
TabLayoutMediator(
            tabbedFragmentView.tabs,tabbedFragmentView.view_pager)
 { tab, position ->
            tab.text = tabFragmentList[position].title
 }.attach()

我找不到设置副标题的方法,只有一个设置文本功能可用,它将是选项卡布局选项卡的主标题,如果我也想要一个副标题。

【问题讨论】:

    标签: android kotlin


    【解决方案1】:

    您需要为选项卡设置自定义视图:

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

    【讨论】:

      【解决方案2】:

      tabLayout 与 viewpager2 : 你可以参考这个link

      TabLayoutMediator(tabLayout, viewPager) { tab, position ->
      tab.text = tabTitles[position]
      viewPager.setCurrentItem(tab.position, true)
      }.attach()
      

      【讨论】:

        猜你喜欢
        • 2013-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多