Add a menu to an empty activity
You need to inflate your menu. These tutorials show how to use menus. So something like this, and choose a better name than menu_menu:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_menu, menu);
return true;
}
when you make a menu's layout you need to define it for the Activity you want to place it in. You may do so by:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater findMenuItems = getMenuInflater();
findMenuItems.inflate(R.menu.main_menu, menu);
return super.onCreateOptionsMenu(menu);
}
the main_menu
is your menu's layout name, and findMenuItems
is an optional name.
And to make your menu's items clickable for an About menu and exiting the app you'll need this:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.aboutMenuItem:
Intent aboutIntent = new Intent(MainActivity.this, AboutActivity.class);
startActivity(aboutIntent);
break;
case R.id.exitMenuItem:
finish();
break;
}
return super.onOptionsItemSelected(item);
}