Skip to content
Advertisement

How to add a badge above a button?

In my MainActivity class, I have this button:

JavaScript

I now want to add a badge with the number 1, using Material Design (see the documentation).

This is how I tried:

JavaScript

but what I get is the error

‘attachBadgeDrawable(com.google.android.material.badge.BadgeDrawable, android.view.View, android.widget.FrameLayout)’ in ‘com.google.android.material.badge.BadgeUtils’ cannot be applied to ‘(com.google.android.material.badge.BadgeDrawable, android.view.View)’

Advertisement

Answer

If you tried this on a device with <18 API this might work;

In your XML wrap the button with a FrameLayout;

JavaScript

In your Activity;

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement