Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number in Action Bar like Gmail

I'm trying to display a data count in the top right corner of my Action Bar.

If I wouldn't be using a split action bar I would just create a TextView in the bar, but it's currently not possible to have items in the top Action Bar when you have split.

To clarify, what I mean is this:

Gmail unread count

Did Google use a different Action Bar implementation or is there a way to do this? I think I remember reading about it, but I can't find how it was called.

like image 766
Tim van Dalen Avatar asked May 25 '12 15:05

Tim van Dalen


People also ask

How do I add settings to action bar?

All action buttons and other items available in the action overflow are defined in an XML menu resource. To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.

Where is action bar in Android?

Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button.


1 Answers

Use a custom view with your spinner and text view for the top AB and enable the android:uiOptions="splitActionBarWhenNarrow" in the manifest declaration for your activity

//set the actionbar to use the custom view (can also be done with a style)
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

//set the custom view to use
getActionBar().setCustomView(R.layout.custom_ab);

Where custom_ab.xml is a layout with your ImageView, Spinner and TextView for the count.

like image 168
roflharrison Avatar answered Sep 20 '22 20:09

roflharrison