18

I have this layout that add 1 or more items into the ActionBar

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
        <item
           android:id="@+id/item_test"                
           android:showAsAction="always|withText"
           android:title="SearchIcon"/> 
</menu>

And then I will add another item dynamically into the ActionBar from another Fragment or Activity

MenuItem populateItem = menu.add("My New Item - Reload Icon");

But I want the item that I just added to stay in front of the items I had before, like the picture:

enter image description here

If I add it like I did, the icons will be shown as the last picture, how can I get the alignment like in the second picture?

feco
  • 4,384
  • 5
  • 27
  • 44

1 Answers1

35

You can re-order the menu items with the android:orderInCategory attribute in each you need to move. You have to play around with that option alogn with menuCategory.

For example, assign to all items:

android:menuCategory="system"

Then, just set lower orderInCategory values to the Items you want to keep on the left.

Order in category determines the order appearance, from low to high.

Iñigo
  • 12,723
  • 2
  • 31
  • 31