Loading...

Adding Badge (Notification Count) to Android ActionBar Icon

In this tutorial, I am going to show how to implement badge (notification count) to android ActionBar item icon. Badge is used to show notification, message and item count like in supping app or website.

Adding badge in android action bar is tricky part. You have to create a layout for badge notification count and link it to action bar item from java code.

First, you need to do is collect icons to use in actionbar item and add them in res/drawable directory of your project.

Related:
Adding Badge (Item Count) to Android Button
Android Toolbar Example: How to Use Toolbar as ActionBar/AppBar
Change the Background and Text Color of Android ActionBar Option Menu

Android Example: How to Add Badge (Notification Count) to Android ActionBar


Following is the different XML and java file to implement badge notification count in android actionbar.

XML Layout File


Create a new XML layout file in res/layout of your project and add the following code. Here I have added Button, ImageButton, TextView in LinarLayout and Relative Layout to make item count and icon for actionbar.

res/layout/notification_update_count_layout.xml

Following is the default content of main XML layout file.

res/layout/notification_count_badge_in_actionbar.xml

Menu Items


Following is the content of main_menu.xml file where different items are option menu/ overflow menu items added.

res/manu/main_menu.xml

Java Activity File


Add the following java code in your main activity file.

src/NotificationCountBadgeAndroidActionBar.java

Android Example: How to Add Badge (Notification Count) to Android ActionBar

Now, run your Adding Badge (Notification Count) to Android ActionBar Icon application, you will see the icons of action bar with badge notification number.
XML 3345309582225829424
Home item