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.
The action overflow menu is only available when there is no hard menu button available on the device. I found this stated in the Framework Topics under User Interface > Action Bar, check out the 3rd bullet here.
There is an action bar library written by Jake Wharton called ActionBarSherlock. Perhaps this is able to supply you with an action overflow menu style even when on older devices (which include a hard menu button), however I have not looked into this.
Edit: ActionBarSherlock 4.0 (currently a release candidate) has functionality built in to force action overflow. If you want to extend the ActionBarCompat example yourself, you could take a look on github to get an idea how Jake implemented it. I would suggest just looking into using his library all together, as it is very well done.
If you choose to use Jake's library, look into setting up the Activity theme as @style/Theme.Sherlock.ForceOverflow to force the overflow menu on older devices.
Edit2: Using ForceOverflow
theme causes issues (example #1) on devices with hardware menu button. Thus, Jake Wharton is going to remove ForceOverflow
in the future versions.
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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With