通过xml加载菜单Menus
<MENU xmlns:android="http://schemas.android.com/apk/res/android">
?<GROUP android:id="@+id/myGroup">
??<ITEM android:id="@+id/New" android:title="New" android:orderInCategory="0"></ITEM>
??<ITEM android:id="@+id/Save" android:title="@string/save" android:orderInCategory="1" />
?</GROUP>
</MENU>
?
?/res/menu?? menus.xml?? android:orderInCategory="1"菜单的位置
@Overridepublic boolean onOptionsItemSelected(MenuItem item) {switch (item.getItemId()) {case R.id.New:doSmth();break;case R.id.Save:doSmth();break;}return super.onOptionsItemSelected(item);}
?
Group Category tag
view sourceprint?1
<GROUP android:id=
"@+id/some_group_id "
android:menuCategory=
"secondary"
> </GROUP>
Checkable Behavior tag
You can use it for group:
1
<GROUP android:id=
"@+id/noncheckable_group"
android:checkableBehavior=
"none"
></GROUP>
And also for menu item:
view sourceprint?1
<ITEM android:id=
".."
android:title=
"…"
android:checked=
"true"
/>
Submenu tag
view sourceprint?1
<ITEM android:title=
"Submenu"
>
2
????
<MENU>
3
????????
<ITEM… />
4
????
</MENU>
5
</ITEM>
Menu Icon tag
view sourceprint?1
<ITEM android:id=
".. "
android:icon=
"@drawable/yourImageFile"
/>
Menu Enabling/Disabling tag
view sourceprint?1
<ITEM android:id=
".. "
android:icon=
"@drawable/yourImageFile"
android:enabled=
"true"
/>
Menu Item Shortcut tag
view sourceprint?1
<ITEM android:id=
"… "
android:alphabeticShortcut=
"n"
/>
Menu Visibility tag
view sourceprint?1
<ITEM android:id=
"… "
android:visible=
"true"
/>
?