I just want to add badge for a menuItem
of BottomNavigationView
in my app. I'm using BottomNavigationView
of Material Components library(version 1.1.0-alpha08) since its the latest version released just 7 days ago from now I didn't found any tutorial for the same, Now because there are changes made in this version of BottomNavigationView
's showBadge method we cannot use that method.
I've tried calling getBadge
and getOrCreateBadge
method over instance of BottomNavigationView
.
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_nav);
if (bottomNavigationView.getBadge(3) == null) {
audioPlayingCountBadge = bottomNavigationView.getOrCreateBadge(3);
audioPlayingCountBadge.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
} else {
audioPlayingCountBadge = bottomNavigationView.getBadge(3);
}
audioPlayingCountBadge.setVisible(true);
I'm noob in android development so if anyone can provide solution for this problem in detail that would be very grateful to me.
build.gradle
:implementation 'com.google.android.material:material:version'
Get VersionMaterial Component Theme
like:Your App Level Theme
Activity code:
XML layout: