Search code examples
androidactionbarsherlockandroid-actionbarmenuitem

Android: Custom view for a menu item


I want to be able to specify a custom view for a MenuItem.

I want to display an indicator on a shopping cart menu item in the action bar displaying how many items are in the cart currently.

Is the only way that I can do this is through adding a custom view instead of utilising the MenuItem lifecycle etc.?


Solution

  • To use a custom view on a MenuItem call setActionView(View view).

    You can supply either an already inflated view or a layout resource ID.