I would like to show count badge in front of Floating Action Button in android. I used FrameLayout in order to achieve that. My code is here
You can use the BadgeDrawable provided by the Material Components Library.
Something like:
fab.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
BadgeDrawable badgeDrawable = BadgeDrawable.create(MainActivity.this);
badgeDrawable.setNumber(2);
//Important to change the position of the Badge
badgeDrawable.setHorizontalOffset(30);
badgeDrawable.setVerticalOffset(20);
BadgeUtils.attachBadgeDrawable(badgeDrawable, fab, null);
fab.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
Currently (1.3.0-alpha02) there isn't a method to change the radius, but you can override this dimen in your project (dimens.xml):
12dp