6

I have an ActionBar using ActionBar Sherlock where I need it to display overflow because I have more actions than room. But, it doesn't show the overflow icon. Here is my configuration:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_search"
      android:icon="@drawable/action_search"
      android:title="@string/menu_search"
      android:showAsAction="ifRoom|withText"/>
<item android:id="@+id/menu_library"
      android:icon="@drawable/hardware_headphones"
      android:title="@string/my_music"
      android:showAsAction="ifRoom|withText"/>
<item android:id="@+id/menu_downloads"
      android:icon="@drawable/av_download"
      android:title="@string/downloads"
      android:showAsAction="ifRoom|withText"/>
</menu>

And here is code to set it up:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getSupportMenuInflater();
    menuInflater.inflate(R.menu.shopping_menu, menu);
    MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
    searchMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(ShopActivity.this, SearchDialog.class));
            return false;
        }
    });
    MenuItem downloadMenuItem = menu.findItem(R.id.menu_downloads);
    downloadMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity( new Intent(ShopActivity.this, DownloadQueueActivity.class) );
            return false;
        }
    });
    MenuItem myMusicItem = menu.findItem(R.id.menu_library);
    myMusicItem.setOnMenuItemClickListener( new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(ShopActivity.this, MyMusicActivity.class));
            return false;
        }
    });

    return true;
}

I've looked over the demos in ActionBar Sherlock, but I can't tell what they do differently to get the overflow than what I'm doing. So what's happening here why its not showing?

chubbsondubs
  • 37,646
  • 24
  • 106
  • 138
  • 3
    If you have a physical menu key, the overflow indicator does not show. That is a behaviour by design. See [here](http://stackoverflow.com/questions/8758263/how-to-force-overflow-menu-on-android-actionbar-compat?rq=1) for more details on another question asked. – t0mm13b Jul 14 '12 at 01:53
  • Drop this in an answer, and I'll award you the points. Thanks – chubbsondubs Jul 14 '12 at 03:22
  • Here is [ActionBar](http://developer.android.com/guide/topics/ui/actionbar.html). It's same as Tom's comment, but it's from Android's official documentation. –  Jul 14 '12 at 06:13

3 Answers3

23

If you have a physical menu key, the overflow indicator does not show. That is a behaviour by design. See here for more details on another question asked.

Community
  • 1
  • 1
t0mm13b
  • 34,087
  • 8
  • 78
  • 110
  • 4
    The other side of this answer is to add this attribute to your activity: android:theme="@style/Theme.Sherlock.ForceOverflow" and it will put the actions in the ActionBar that don't fit with an overflow icon to access it as a drop down. Overall I think this design decision about putting junk the menu button is stupid because Google is trying to move people to the ActionBar because from their own admission and research nobody knows about the menu button. So why have the overflow there by default?! "Oh I got it. Let's put it where nobody goes." Well not everything Google does can be brilliant. – chubbsondubs Jul 14 '12 at 16:54
0

Hmm I think there are two issues here. First, as t0mm13b states, if the device has a physical menu key, the overflow indicator does NOT show. This is by design. Although in my experience, it doesn't apply to every device (unfortunately...)

The second issue is that, if you want to force an item to the overflow, you need to set the showAsAction to "never". Otherwise, the only elements that appear in the overflow are ones that simply "don't fit" in the action bar. And given that you have 3 items that you want to display with text.. you're pretty much guranteed to have at least one overflow item, and therefore the overflow icon (with the caveat of the first paragraph)

kwazi
  • 592
  • 5
  • 8
0

Try by changing the android:showAsAction tag to app:showAsAction according to the Android guide in the menu_main.xml file as shown below

Add this line if not present

menu xmlns:app="http://schemas.android.com/apk/res-auto"

    <item android:id="@+id/action_search"
        android:icon="@drawable/search_icon"
        android:title="@string/action_search"
        app:showAsAction="always"/> <!--change here android: to app:-->

    <item android:id="@+id/action_location"
        android:icon="@drawable/location_icon"
        android:title="@string/action_locate"
        app:showAsAction="always"/>
</menu>
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Pratik ED
  • 151
  • 1
  • 1
  • 13