2

I'm having a problem when I try to set one item in my actionbar as always visible and 4 more icons as dropdown items with the following layout:

 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/search_movies"
        android:icon="@drawable/action_search"
        android:showAsAction="always"
        android:title="Search"/>
    <item
        android:id="@+id/movies"
        android:icon="@drawable/action_video"
        android:showAsAction="collapseActionView"
        android:title="Movies"/>
    <item
        android:id="@+id/theaters"
        android:icon="@drawable/action_location_map"
        android:showAsAction="collapseActionView"
        android:title="Theaters"/>
    <item
        android:id="@+id/preferences"
        android:icon="@drawable/action_settings"
        android:showAsAction="collapseActionView"
        android:title="Preferences"/>
    <item
        android:id="@+id/contact"
        android:icon="@drawable/action_about"
        android:showAsAction="collapseActionView"
        android:title="Contact"/>

    </menu> 

The result is just the first item showing and the rest are not visible, not even as a dropdown. This is using ActionBarSherlock and a 2.3 Android device.

The question is, how can I get the icons to follow this layout:

enter image description here

EDIT:

The problem I had was because when you are using the actionbar with a device that has a "menu" hardware button the 3-dot dropdown does not shows off, the 4 other items are only displayed if you press the menu hardware button. Does anyone knows if this behaviour can be modified?

Adinia
  • 3,722
  • 5
  • 40
  • 58
BigBen3216
  • 868
  • 1
  • 8
  • 23

2 Answers2

1

Hmmm, maybe I misunderstood, but if you wish to places those remaining four items into the overflow action menu (the 3-dot icon) then using android:showAsAction="never" instead of "collapseActionView" should do it.

...Tried a couple ways, but this did the trick: Force overflow menu in ABS

Community
  • 1
  • 1
es0329
  • 1,366
  • 1
  • 18
  • 35
  • following your recomendation i get the same result, only one icon is visible and the 3-dot icon is not showing. – BigBen3216 Apr 26 '13 at 15:26
  • Is the very first line inside of the `onCreateOptionsMenu(Menu menu)` for this Acivity `getSupportMenuInflater().inflate(R.menu.yourMenuLayout, menu);`? – es0329 Apr 26 '13 at 16:06
  • Yes, I have that line, in fact it is correctly reading the menu.xml file, you can see in my edit that the problem is only present in devices with a "menu" hardware button, when you click that button the items appear but the 3-dot icon is not visible. – BigBen3216 Apr 26 '13 at 16:13
  • Does the second answer in this thread apply? [Force overflow menu in ABS](http://stackoverflow.com/questions/13179620/force-overflow-menu-in-actionbarsherlock) – es0329 Apr 26 '13 at 16:21
  • Yes, that answer works perfectly, could you add this to your answer so I can mark it as accepted? – BigBen3216 Apr 26 '13 at 17:02
1

I've met the same problem and my solution is quite simple. (I didn't use HoloEverywhere.)

The idea comes from the ABS sample project, whose drop-down menu can be displayed on pre-4.0 devices as well by using a submenu. So, my idea is using a submenu to disguise the 3-dot icon. Here's the code:

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    SubMenu sub = menu.addSubMenu("More");
    sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    sub.getItem().setIcon(R.drawable.ic_menu);

    getSupportMenuInflater().inflate(R.menu.activity_main, sub);

    return true;
}

Since the "More" menu doesn't have a MenuItem.SHOW_AS_ACTION_WITH_TEXT attribute, so the word "More"(or whatever you named) will actually not be displayed on the action bar. The only displayed icon R.drawable.ic_menu can be copied from ABS source code res/drawable-xxdpi folders named "abs__ic_menu_moreoverflow_normal_holo_dark.png", which is the so-called 3-dot icon. And the R.menu.activity_main is your menu xml.

It works!

Yingyi Xu
  • 387
  • 1
  • 3
  • 15