Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 3.0: Changing order of icons in the action bar

Tags:

android

I am working with the Android 3.0.

I have in the action bar 3 items and one of them is the menu of the application, it also has sub-menu in it.

I want to change the order of the icons so the menu won't be in the right place, I want it to be between the two other items. I tried to change the order in the xml with no success. Does anyone has an idea how to set the order?

like image 817
Yaniv Avatar asked Dec 22 '22 14:12

Yaniv


2 Answers

Try setting android:menuCategory and android:orderInCategory for your menu items to set the ordering.

Example:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/launch_search"
          android:icon="@android:drawable/ic_menu_search"
          android:title="@string/search_programs"
          android:menuCategory="container"
          android:orderInCategory="2"
          android:showAsAction="always" />
    <item android:id="@+id/preferences_screen"
          android:icon="@android:drawable/ic_menu_preferences"
          android:title="@string/preferences" />
    <item android:id="@+id/refresh"
          android:icon="@drawable/ic_menu_refresh"
          android:menuCategory="container"
          android:orderInCategory="1"
          android:title="@string/refresh_items"
          android:showAsAction="ifRoom" />
</menu>

It will have the same effect as declaring launch_search -action as last, but this way you'll have your actions in the right order for 2.x and older devices while being able to control action ordering for 3.x -devices.

like image 192
plouh Avatar answered Jan 06 '23 01:01

plouh


The menu will always go to the right, you cannot control its placement.

like image 35
Romain Guy Avatar answered Jan 06 '23 01:01

Romain Guy