在操作栏图标的优先级(保持项目的顺序)优先级、图标、顺序、操作

2023-09-12 03:13:59 作者:꧁疲惫꧂

我试图控制其操作栏项目将显示是否有空间有限,并试图在这一问一答的解决方案:的在操作栏的图标优先

I'm trying to control which action bar items get shown if there is limited space, and have tried the solution in this question and answer: Icons priority on action bar

一切正常,除了我想保持的图标的顺序的方式是不同的优先级,而上述解决方案将导致项目进行重新排序。有什么办法来设置项显示的一个优先事项,在不改变顺序的项目出现在动作条?

Everything works fine other than I want to keep the order of the icons in a manner which is different to the priority, whereas the solution above causes the items to be reordered. Is there any way to set a priority for item display, without altering the order that items appear in the actionbar?

我试图改变在XML项目的顺序,与本次项目的顺序没有影响,因为渲染(不orderInCategory,更改文件的顺序并导致项目的顺序变化为渲染)。

I've tried altering the order of the items in the xml, and this has no impact on the order of items as rendered (without the orderInCategory, changing the order in the file does result in a change in the order of items as rendered).

我正在开发针对ICS。

I'm developing against ICS.

menu.xml文件

menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/action_edit"
        android:icon="@android:drawable/ic_menu_edit"
        android:title="@string/action_edit"
        android:showAsAction="ifRoom"
        android:orderInCategory="1"
        />

    <item
        android:id="@+id/action_undo"
        android:icon="@android:drawable/ic_menu_revert"
        android:title="@string/action_undo"
        android:showAsAction="ifRoom"
        android:orderInCategory="2"
        />

    <item
        android:id="@+id/action_delete"
        android:icon="@android:drawable/ic_menu_delete"
        android:title="@string/action_delete"
        android:showAsAction="ifRoom"
        android:orderInCategory="3"
        />

    <!-- I want this item to be on the right, 
    but shown in preference to any other items; 
    setting it's orderInCategory to 0 ensures that it 
    is shown in preference to other items, 
    but always places it on the left -->
    <item
        android:id="@+id/action_addnew"
        android:icon="@android:drawable/ic_menu_add"
        android:title="@string/action_addnew"
        android:showAsAction="ifRoom"
        android:orderInCategory="0"
        />
</menu>

感谢。

推荐答案

我从阅读你的问题得到的是要显示action_addnew应该出现在右放大器;它应该始终显示给大家。 试试这个

What i got from reading your question is you want to display action_addnew should appear in the right & it should always appear to everyone. Try this one

    <menu xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:id="@+id/action_edit"
            android:icon="@android:drawable/ic_menu_edit"
            android:title="@string/action_edit"
            android:showAsAction="ifRoom"
            />

        <item
            android:id="@+id/action_undo"
            android:icon="@android:drawable/ic_menu_revert"
            android:title="@string/action_undo"
            android:showAsAction="ifRoom" />

        <item
            android:id="@+id/action_delete"
            android:icon="@android:drawable/ic_menu_delete"
            android:title="@string/action_delete"
            android:showAsAction="ifRoom"
            />

        <item
            android:id="@+id/action_addnew"
            android:icon="@android:drawable/ic_menu_add"
            android:title="@string/action_addnew"
            android:showAsAction="always"
            />
    </menu>
 
精彩推荐