Alex Rivera | Logout

How to force overflow menu on android actionbar compat?

Asked 2012-01-06T13:07:09.590
34

Android action bar compat
Is it possible? On older devices (pre 3.0) the items that don't fit the action bar are only shown when the menu key is pressed, I want these items to be grouped in the actionbar's overflow menu.

Edit
Report

1 Answer

12

Okay, this is simple but hard to figure out.

You first need a menu item you want to use as the overflow inflater. Example

<item
        android:id="@+id/a_More"
        android:icon="@drawable/more"
        android:showAsAction="always"
        android:title="More">
        </item>

Once you have your item, add a sub-menu containing your items you want in the overflow menu. Example:

<item
    android:id="@+id/a_More"
    android:icon="@drawable/more"
    android:showAsAction="always"
    android:title="More">
    <menu>
        <item
            android:id="@+id/aM_Home"
            android:icon="@drawable/home"
            android:title="Home"/>
    </menu>
</item>

On click this will inflate other items within. My application is using ActionBarSherlock 4.0 so before this will work for you, you will need to access the "SplitActionBar". (Will still work on default android Actionbar)

Here's how: In your AndroidManifest.xml file, you need to add this code under the activity you need the overflow menu in. Honestly it shouldn't matter if you have the actionbar split or not but I prefer it.

android:uiOptions="splitActionBarWhenNarrow"

NOTE: Your item that inflates your overflow menu MUST showAsAction="always"

Vwola! you have an overflow menu! Hope I helped you out. :)

answered 2013-02-13T19:07:11.943

Your Answer