Search code examples
androidandroid-actionbaractionbarsherlock

Custom views in actionbar


I have an action bar. One of the items in the actionbar is for notifications. I want to add a little icon in the top right of the actionbar item which represents how many notifications the user currently has.

I went ahead and made a custom layout for the action bar item. Went to go add it and to my surprise there is no way for me to add a custom view as a button on a Action bar.

I am using Actionbar-Sherlock for compatibility to older device.

This is what I am going for:

enter image description here


Solution

  • You're looking for ActionProvider. Here you can supply your own views and listeners.

    Check out the ABS demo, https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock-samples/demos/src/com/actionbarsherlock/sample/demos/ActionProviders.java