废话不多说直接上代码
//激活显示菜单
@Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.option,menu);
return true;
}
//当菜单被选中时操作
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.save:
Toast.makeText(this,"保存成功",Toast.LENGTH_SHORT).show();
break;
case R.id.setting:
Toast.makeText(this,"设置成功",Toast.LENGTH_SHORT).show();
break;
}
return super.onOptionsItemSelected(item);
}
这就简单的设置了一个菜单,点击界面右上角的三个小点,就会弹出:保存和设置两个控件,点击以后分别给出以上回应
标签:Toast,菜单,show,menu,item,SHORT,Studio,Android From: https://www.cnblogs.com/nashacjj/p/17209777.html