how to display button when menu button is pressed in android
h开发者_运维问答i friends i want to pop up a button from the bottom of my screen when the default menu button is pressed on the android key pad. i want to navigate from that pop button to other screens.
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;
}
And to handle your menu:
@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;
}
regards
精彩评论