Tablayout+ViewPager使用的时候+Tablayout又需要展示消息小圆点的问题

Tablayout当需要展示除去Title以外的信息的时候这时候就不能重写PagerAdapter的setPagerTitle方法了。这样达不到我们的需求。

此时就需要这样来指定我们的Tablayoutd View

tabCustomView = layoutInflater.inflate(R.layout.layout_tablayout_custom_view, null, false)
tablayout.setupWithViewPager(activity_fit_receipt_viewpager)
tablayout.getTabAt(0).nN().text = "仓库发出"
tablayout.getTabAt(1).nN().customView = tabCustomView

复制代码

activity_fit_receipt_tablayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
    override fun onTabReselected(p0: TabLayout.Tab?) {

    }

    override fun onTabUnselected(p0: TabLayout.Tab?) {
        if (p0!!.customView != null && tabCustomView != null) {
            tabCustomView!!.find<TextView>(R.id.tv_tab_title).textColor = ContextCompat.getColor(this@FitReceiptListDispatchActivity, R.color.color_gray3)
        }
    }

    override fun onTabSelected(p0: TabLayout.Tab?) {
        if (p0!!.customView != null && tabCustomView != null) {
            tabCustomView!!.find<TextView>(R.id.tv_tab_title).textColor = ContextCompat.getColor(this@FitReceiptListDispatchActivity, R.color.color_white)
        }
    }
})复制代码

在监听的时候去指定小圆圈的颜色以及text

并且除了要使用customView之外,tab信息的初始化也一定要放在setUpWithViewPager之后再来执行。因为翻下Tablayout的源码就知道了。




就这样。。。


转载于:https://juejin.im/post/5a28f79df265da43040683a8

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值