我試圖控制其動作欄項目將顯示是否有空間有限,並試圖在這一問一答的解決方案:Icons priority on action bar圖標的優先行動欄上(保持項目的順序)
一切正常除了我想要以不同於優先級的方式來保持圖標的順序之外,還有其他問題,而上面的解決方案會導致項目重新排序。有沒有辦法設置項目顯示的優先級,而不改變項目在操作欄中的顯示順序?
我已經嘗試改變xml中項目的順序,並且這對渲染的項目順序沒有影響(沒有orderInCategory,更改文件中的順序的確會導致順序的變化項目呈現)。
我正在開發針對ICS。
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>
感謝。
請發佈您的代碼 – NarenderNishad
@NarenderNishad完成! – GHC
@GCH請查看我的回答 – NarenderNishad