Adding Badge (Item Count) to Android Button

Badge can be used to show number notification, item/product count, message etc. We can see many applications used badge, not only android app it can be used in ipad, iphone, window and even also in web app. Facebook used badge to count notification, friend request, message etc. and many ecommerce website also used to count number of order product, item added to bucket etc. In this tips, I am going to show how to add badge to android button, image button, imageview and like the same way you can use where you want in your application.

Adding badge in android application is little bit tricky part. There is no any shortcut ways of implementing badge in android application; we have to do our self. Here you will learn how to implement notification alert badge in an android application.

To implementing badge in android app here, I have used relative layouts, buttons and text views.

Android Toolbar Example: How to Use Toolbar as ActionBar
Android Material Design ActionBar/App Bar
Adding Badge (Notification Count) to Android ActionBar Icon

Android Example: How to Add Badge (Item Count) to Android Button

Following are the different XML file to add a notification alert badge in android button.

Create a new XML file in your app drawable directory and give the name badge_item_count. Following is the complete content of badge_item_count.xml file where I have creates a rectangle with 8dp corner radius.

res/drawable/ badge_item_count.xml

Then you have to modify your app XML layout file to implement badge in android button. Here I have added several RelativeLayout, Buttons and TextView. Following is the complete content of android XML layout file.


Following is the default content of java activity file.

src/ AndroidNotificationCountBadge.java

Android Example: How to Add Badge (Item Count) to Android Button

Now, run your Adding Badge (Item Count) to Android Button application, you will see like the screenshot above. Make sure you have added icons in drawable folder with appropriate name which is used in XML layout file.
XML 3314058288344101052
Home item