Ali
Ali

Reputation: 2042

Custom action item ActionBarSherlock

I'm trying to add some custom actions into my ActionBar, Is it possible to implement these actions with a custom layout? Because I want to add some badge like notification counter to these actions.

e.g

enter image description here

Any idea to how accomplish this?

Upvotes: 3

Views: 1023

Answers (1)

dmon
dmon

Reputation: 30168

Sure, from XML you can set an arbitrary layout as the action view:

<item android:id="@+id/menu_refresh_progress"
  android:actionLayout="@layout/menu_progress"
  android:showAsAction="always"/>

But since presumably you want to update the badge to something current, you can also set an arbitrary view if you're creating the menu by hand in onCreateOptionsMenu():

public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    MenuItem someMenuItem = menu.getItem(R.id.menu_option_id);
    someMenuItem.setActionView(theView);
    return true;
}

Upvotes: 5

Related Questions