Android: Custom view for a menu item

Brad picture Brad · Jun 27, 2013 · Viewed 12.7k times · Source

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.?

Answer

Brad picture Brad · Jun 27, 2013

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.