How to implement dynamic values on menu item in Android

intrepidkarthi picture intrepidkarthi · Nov 26, 2012 · Viewed 27k times · Source

I have a menu item in the action bar. Along with the menu item image, I need to show some number associated with it which will change often. I am not using Action bar sherlock. I don't want to use that. Other than this everything else just works fine. In the shown image, the white icon color icon is mine. I need to generate the number with the red color background dynamically. How can I do that in Android?

Here is the sample image:

enter image description here

Update:

I have this menu item in my menu.xml. This should work like a notification menu item which shows the number of notification count. I set the menu icon like,

 menuItem.setIcon(image);

Now, on top of the menu item I need to place one text view which has the total count of notifications.

is it possible to implement this functionality with viewbadger? Github url

Answer

speedynomads picture speedynomads · May 20, 2013

I discovered how to add an actionView to a menu item and retrieve as set values to the view in code.

See here: https://stackoverflow.com/a/16648170/857681