@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
super.onCreateOptionsMenu(menu);
menu.add(0, Menu.FIRST+1, 0, "显示button1"); //添加菜单项
menu.add(0, Menu.FIRST+2, 1, "显示button2");
return true; //返回false则不显示menu
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){ //获得添加菜单项时的第二个参数
case Menu.FIRST+1:
Toast.makeText(this, "button1被点击了", Toast.LENGTH_SHORT).show(); //Toast.LENGTH_SHORT 短时间显示
break;
case Menu.FIRST+2:
Toast.makeText(this, "button2被点击了", Toast.LENGTH_LONG).show(); //Toast.LENGTH_LONG 长时间显示
break;
}
return false;
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
super.onCreateOptionsMenu(menu);
menu.add(0, Menu.FIRST+1, 0, "显示button1"); //添加菜单项
menu.add(0, Menu.FIRST+2, 1, "显示button2");
return true; //返回false则不显示menu
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){ //获得添加菜单项时的第二个参数
case Menu.FIRST+1:
Toast.makeText(this, "button1被点击了", Toast.LENGTH_SHORT).show(); //Toast.LENGTH_SHORT 短时间显示
break;
case Menu.FIRST+2:
Toast.makeText(this, "button2被点击了", Toast.LENGTH_LONG).show(); //Toast.LENGTH_LONG 长时间显示
break;
}
return false;
}