Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

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

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

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/menu_search"
    android:icon="@drawable/search"
    android:title="@string/start_new_project"
    app:showAsAction="always" />
<item
    android:id="@+id/menu_dts_overflow"
    android:icon="@drawable/ic_action_overflow_round"
    android:orderInCategory="11111" 
    android:title="Service"
    app:showAsAction="always">
    <menu>
        <item
            android:id="@+id/menu_newProject"
            android:icon="@drawable/newproject"
            android:title="@string/start_new_project"
            app:showAsAction="never" />


        <item
            android:id="@+id/menu_help"
            android:icon="@drawable/help"
            android:title="Service Tasks"
            app:showAsAction="never" />


        <item
            android:id="@+id/menu_signOut"
            android:icon="@drawable/signout"
            android:title="@string/menusignout"
            app:showAsAction="never" />

    </menu>
</item>

I tried to construct a search item and a overflow item which you can see in the above code. I'm new to Action bar menu items so i tried to Google it and was able to make it work as I need.

In this I have to know one more thing.

1. What is orderInCategory with some numbers and what for it is used..?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

    horizontal menu items

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

    vertical overflow menu


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...