许多菜单始终有一个相同的项目。
是否有一种方法将该项目定义为额外菜单,并将其包含在所有其他菜单中?
类似于此:
menu/main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_main"
android:title="@string/text_mainmenu" />
</menu>
菜单/其他.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
parent="@menu/main">
<item android:id="@+id/menu_other"
android:title="@string/text_othermenu" />
</menu>
我知道可以通过编程的方式实现,但我认为使用XML的方式更好。
onCreateOptionsMenu()
的末尾,这样“不同”的菜单选项就会显示在菜单顶部而不是底部。 - Georgesuper() clear() inflate()
,这样做没有利用好对象结构的目的。 - ebyrob