通过xml加载菜单Menus


 
  
  
 

 

 /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 "@+id/some_group_id " android:menuCategory="secondary">

Checkable Behavior tag
You can use it for group:

view source
print ?
1 "@+id/noncheckable_group" android:checkableBehavior="none">

And also for menu item:

view source
print ?
1 ".." android:title="…" android:checked="true" />

Submenu tag

view source
print ?
1 "Submenu">
2     
3         
4     
5

Menu Icon tag

view source
print ?
1 ".. " android:icon="@drawable/yourImageFile" />

Menu Enabling/Disabling tag

view source
print ?
1 ".. " android:icon="@drawable/yourImageFile" android:enabled="true" />

Menu Item Shortcut tag

view source
print ?
1 "… " android:alphabeticShortcut="n" />

Menu Visibility tag

view source
print ?
1 "… " android:visible="true" />

 

你可能感兴趣的:(指导篇)