アクションバーにメインメニューを作成し、ハードウェアボタンのクリックで開く「オプション」メニューを作成するにはどうすればよいですか?
ワッツアップのように。アバター、名前、アイコンを含むアクションバーがあり、「メニュー」ボタンを押すと、「連絡先、メディア、検索を表示」などの別のメニューが表示されます.
これは私の実際のコードです:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.calendar, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_legend) {
// Open dialog
} else if(id == R.id.action_settings) {
startActivity(new Intent(this, SettingsActivity.class));
} else if(id == R.id.action_add) {
startActivity(new Intent(this, AddActivity.class));
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onKeyDown(int keycode, KeyEvent e) {
switch(keycode) {
case KeyEvent.KEYCODE_MENU:
// Here open the options menu
return true;
}
return super.onKeyDown(keycode, e);
}