1、在Activity中使用menu
//创建菜单项 public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, 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_settings) { return true; } return super.onOptionsItemSelected(item); }
2、销毁活动,即从堆栈中去掉该Activity,并不一定是退出应用。
finish();
3、
时间: 2024-10-14 06:58:52