What is orderInCategory in ActionBar menu item & why it is use for..?

后端 未结 3 822
甜味超标
甜味超标 2020-12-02 14:20

Im working on action menu item and its over flow item this is my main_menu.xml




        
相关标签:
3条回答
  • 2020-12-02 14:35

    android:orderInCategory is an integer attribute that dictates the order in which the menu items will appear within the menu when it is displayed.

    <menu 
        xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item
            android:id="@+id/menu_item_first"
            android:orderInCategory="1"
            android:showAsAction="never"
            android:title="@string/string_one"/>
    
        <item
            android:id="@+id/menu_item_second"
            android:orderInCategory="2"
            android:showAsAction="never"
            android:title="@string/string_two"/>
    
    </menu>
    
    • Menu items in ToolBar are arranged from left to right (or start to end in RTL mode) in the ascending order (i.e. 1,2,3 -> left to right).

    • Menu Items in Overflow menu are arranged from top to bottom in the ascending order (i.e. 1,2,3 -> top to bottom).

    0 讨论(0)
  • 2020-12-02 14:51

    android:orderInCategory Higher value, lower priority.

    I have a Activity and a Fragment in it, both of them have option menu, and the item numbers are 1 and 3.

    If I set android:orderInCategory=0, the activity menu are above the fragment menu, same effect before I set the value.

    But if I set android:orderInCategory=1,the activity menu are below the fragment menu, and that is what I want.(I also test android:orderInCategory=5 tested too, still the same effect.)

    0 讨论(0)
  • 2020-12-02 15:01

    android:orderInCategory is actually useful in two ways.

    1. For menu items in ActionBar. Items will appear from left to right in ActionBar depending on the ascending order.

    2. For menu items in overflow menu. Overflow menu items will be displayed from top to bottom depending upon the ascending order you have specified.

    0 讨论(0)
提交回复
热议问题