To show the numbering on the cart depending on the number of products in cart, we used the library Android-ActionItemBadge.
To use this, add in the gradle file :
dependencies {
implementation 'com.mikepenz:actionitembadge:3.3.2@aar'
implementation 'com.mikepenz:iconics-core:{latestVersion}@aar'
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
}
In the menu item, add :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/item_samplebadge"
app:actionLayout="@layout/menu_action_item_badge"
app:showAsAction="always"
android:title="@string/sample_1"/>
</menu>
In OnCreateOptionsMenu, add :
public boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.main, menu);
if (badgeCount > 0) {
ActionItemBadge.update(this, menu.findItem(R.id.item_samplebadge), FontAwesome.Icon.faw_android, ActionItemBadge.BadgeStyles.DARK_GREY, badgeCount);
} else {
ActionItemBadge.hide(menu.findItem(R.id.item_samplebadge));
}
new ActionItemBadgeAdder().act(this).menu(menu).title(R.string.sample_2).itemDetails(0, SAMPLE2_ID, 1).showAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS).add(bigStyle, 1);
return super.onCreateOptionsMenu(menu);
}