<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"菜单的位置
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menus, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public 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 source
print
?
1
<GROUP android:id="@+id/some_group_id " android:menuCategory="secondary"> </GROUP>
Checkable Behavior tag
You can use it for group:
view source
print
?
1
<GROUP android:id="@+id/noncheckable_group" android:checkableBehavior="none"></GROUP>
And also for menu item:
view source
print
?
1
<ITEM android:id=".." android:title="…" android:checked="true" />
Submenu tag
view source
print
?
1
<ITEM android:title="Submenu">
2
<MENU>
3
<ITEM… />
4
</MENU>
5
</ITEM>
Menu Icon tag
view source
print
?
1
<ITEM android:id=".. " android:icon="@drawable/yourImageFile" />
Menu Enabling/Disabling tag
view source
print
?
1
<ITEM android:id=".. " android:icon="@drawable/yourImageFile" android:enabled="true" />
Menu Item Shortcut tag
view source
print
?
1
<ITEM android:id="… " android:alphabeticShortcut="n" />
Menu Visibility tag
view source
print
?
1
<ITEM android:id="… " android:visible="true" />
标签:xml,菜单,source,menu,Menus,tag,Menu,print,view
From: https://blog.51cto.com/u_16166892/6535802