什么是 ActionBar 菜单项中的 orderInCategory &为什么它用于..? [英] What is orderInCategory in ActionBar menu item & why it is use for..?

查看:34
本文介绍了什么是 ActionBar 菜单项中的 orderInCategory &为什么它用于..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理操作菜单项及其溢出项,这是我的 main_menu.xml

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. 什么是带有一些数字的 orderInCategory 以及它的用途..?

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

推荐答案

android:orderInCategory 是一个整数属性,它规定了菜单项在显示时在菜单中的显示顺序.

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>

  • ToolBar 中的菜单项从 leftright(或startend 在 RTL 模式下)按升序排列(即 1,2,3 ->从左到右).

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

    Overflow menu中的Menu Items从topbottom排列升序(即 1,2,3 -> 从上到下).

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

    这篇关于什么是 ActionBar 菜单项中的 orderInCategory &amp;为什么它用于..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆