I want to create a custom overflow menu item in my ActionBar in addition at the Setting item like described in the image below:
But if there is few space in the ActionBar I don't want that the Item1 and Item2 go into the Setting item as overflow, but into "my overflow item".
this is my menu xml code:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:icon="@android:drawable/ic_menu_agenda"
android:title="Item1"
android:showAsAction="ifRoom|withText" />
<item
android:icon="@android:drawable/ic_menu_add"
android:title="Item2"
android:showAsAction="ifRoom|withText" />
<item android:id="@+id/pick_action_provider"
android:icon="@android:drawable/ic_menu_sort_by_size"
android:showAsAction="always"
android:title="Overflow" >
<menu>
<item android:id="@+id/action_sort_size"
android:icon="@android:drawable/ic_menu_camera"
android:title="Item3" />
<item android:id="@+id/action_sort_alpha"
android:icon="@android:drawable/ic_menu_sort_alphabetically"
android:title="Item4" />
</menu>
</item>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/></menu>
This will help you. I had coded this for overflow menu
In menu/main.xml file
And here is your java code:
See these links
http://www.codeproject.com/Articles/173121/Android-Menus-My-Way
http://developer.android.com/guide/topics/ui/actionbar.html#Dropdown
and i suggest you to use actionbarsherlock to create a custom overflow menu
See this answer to know how to create overflow menu item using actionbar sherlock
ActionbarSherlock does not include "overflow" section of Action Bar (on Android 2.1)
Create a style for the overflow menu and pass in a content description
Call ViewGroup.findViewsWithText and pass in your content description. Somewhat like this:
View.findViewsWithText was added in API level 14 only. So please try to do a method by you own as like this:
This is not a tested code. So if there any issues while you implemented,please let me know.
when click item from actionbar
You most probably have to remove the setting item in the menu i.e. @+id/action_settings.
If you still want it to be there, just remove it's "showAsActionAttribute" or exchange it to
For Item1 and Item2: Add their
showAsAction
attributes asandroid:showAsAction="ifRoom|withText"
Hope that helps.
menu.xml
:abc.class
file makes these changes:See Menus documentation.