You first have to declare your desired menu in /menu/menu.xml
then you need a inflater for your menu:
// menuinflater
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
要处理您的菜单:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// only one menu option here for preferences
// for more just add new case with your ids
case R.id.firstmenuitem:
// Launch preferences activity
Intent i = new Intent(youractivity.this, preferences.class);
startActivity(i);
break;
}
return true;
}
当做