Android Tablayout tabs with notification badge like whatsApp

前端 未结 9 961
感情败类
感情败类 2020-12-04 20:15

I want to implement notification badge with android.support.design.widget.TabLayout. I had tried my best effort to implement it but fails.

Any help wou

9条回答
  •  伪装坚强ぢ
    2020-12-04 20:43

    This is an old cuestion, but Its much more simple these days. Im using Kotlin, AndroidX, using the next widget as TabLayout:

    com.google.android.material.tabs.TabLayout
    

    and inside my gradel app file:

    implementation 'com.google.android.material:material:1.1.0-alpha09'
    

    For setting a simple badge, just write..

    yourTabLayout?.getTabAt(currentTabPosition)?.apply{
                            orCreateBadge
                            badge?.isVisible = true
                        }
    

    Then just set isVisible = false to hide, like this:

    private fun changeYourTabMethod(newTabPosition : Int) {
        // do some stuff and then hide the badge...
        yourTabLayout?.getTabAt(newTabPosition)?.apply{
            badge?.isVisible = false
        }
    }
    

提交回复
热议问题