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>
The best way to do what you want to achieve is to inflate a custom
ActionBar
.Do the following steps.
1)Create a XML
RelativeLayout
2) Include a menu item and tag inside the XML
3) Inflate the action bar via the
ActionBar
class.4) That's it you're done!!
Warning: Don't forget to use the compatibility library!! There are some dependencies in it for the above to work.
Try using
do not forget to add
And try to have separate menus for fragment and global (Settings in Global.xml menu file)
Make sure you inflate both in correct order.