Background
----------

many apps (including [**google plus**](https://play.google.com/store/apps/details?id=com.google.android.apps.plus) and [**facebook**](https://play.google.com/store/apps/details?id=com.facebook.katana)) have an action bar item showing the number of in-app-events (or "notifications").

This action item has a number within it and you can click it in order to show the events the app has for the user.

something like that (taken from [**here**](https://lh3.ggpht.com/vHPn_5FJEUOrXCyLC2_zQfNioSP9iL64V8c2b9LRiYK5nd2iOaaLRCEIZ4Qs5BuN8VM=h900-rw)) :

![enter image description here](https://i.stack.imgur.com/xxHTx.png)

The problem
-----------

I wish to make it work on old android versions, so i use actionBarSherlock.

Sadly, each solution i use has its disadvantages, and i couldn't find any solution here (on stackOverflow) that handles this with actionBarSherlock (found other solutions, but not with this library).

I've also found a post about it ([**here**](https://github.com/JakeWharton/ActionBarSherlock/issues/32)) , claiming it's an issue on this library, but it's very old and seems to be closed and marked as fixed, but I can't find out how to use it now.

What I've tried
---------------

i've tried the next solutions:

* actionLayout . it showed fine, but clicking on it didn't show the clicking effect.
* actionViewClass - it didn't even work for some reason.
* adding the menu item and its view programmatically.

The question
------------

What's the best way to achieve this ?

---

EDIT: this is what i've tried using actionLayout :

"action\_item\_notification.xml" - for now it's the same as "abs\_\_action\_menu\_item\_layout.xml" ([**here**](https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock/res/layout/abs__action_menu_item_layout.xml)). later i will add a textView to hold the number of notifications.

in the menu xml file, i have this as one of the items:

```
<item
android:id="@+id/activity_main__menuItem_notifications"
android:actionLayout="@layout/action_item_notification"
android:icon="@drawable/notification_button"
android:showAsAction="always"
android:title="@string/notifications"/>

```

not only it doesn't show the icon, but long clicking on the item will crash the app, with a NPE on the ActionMenuItemView.java file.

---

EDIT:ok, so i've found a solution that is almost perfect.

it shows the action item nicely and it even reacts to clicking as the other action items.

I've sadly had one missing feature - long clicking on action item to show the toast of its title. sadly, i couldn't find a way to overcome this so what i did (that works) is handling the long clicking on the view itself, and call a similar code that is used for **ActionMenuItemView::onLongClick** . 

if anyone has a better and nicer solution, please write it down.

i've written this solution in a new answer here.