How to add notification badge on Bottom Navigation View?

android

Solution

The Latest Material dependency now supports natively add badge count, Need to just updated Material dependency in build.gradle

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

and just add

val navBar  = findViewById<BottomNavigationView>(R.id.bottom_navigation)
navBar.getOrCreateBadge(R.id.action_stamp).number = 2

and in style.xml just change "AppCompat" to "MaterialComponents"

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">

Problem

``` <item android:id="@+id/nav_gallery" app:actionViewClass="android.widget.TextView"/> ``` This is the menu of bottom Navigation. ``` TextView gallery=(TextView) MenuItemCompat.getActionView(navigationView.getMenu(). findItem(R.id.nav_gallery)); //getting menu item of bottom nav view gallery.setText("99+"); ``` But this code doesnot work for bottom navigation view.BottomNavigationView is shown without setting any notification counter.

Original source

Related problems