Search code examples
androidandroid-actionbaractionbarsherlock

ActionBar (Sherlock) displaying icon with number of messages on top


I am working with ActionBar and since I have Messaging functionality I wanted to notify user in ActionBar if he has any unread messages. It would look kinda like this:

Messages unread - example notification

However, I can't seem to find if this is supported. So, does anyone know if this is supported and how I would add an icon over existing ActionBar item in this fashion?


Solution

  • The best approach to this would be to create a modified drawable yourself and set it as the source of that particular ActionBar icon. To do this you can call invalidateOptionsMenu() and re-set the icon from within onCreateOptionsMenu(Menu). You can use a LayerDrawable to superimpose the number on top of your actual icon drawable.