android 笔记 --- Android中Menu应用
Android menu是Android开发中经常使用的,下面的例子是Menu使用的简单示例:
package com.enjoy.menu; import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.widget.TextView; public class SystemMenu extends Activity {public static final int SAVE = Menu.FIRST;public static final int RETURN_MENU = Menu.FIRST+1;public static final int QUIT = Menu.FIRST+2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }@Overridepublic boolean onCreateOptionsMenu(Menu menu) {menu.add(0,SAVE,0,"保存");menu.add(0,RETURN_MENU,1,"返回主菜单");menu.add(0,QUIT,2,"退出");return super.onCreateOptionsMenu(menu); }@Overridepublic boolean onOptionsItemSelected(MenuItem item) {TextView tv = (TextView)findViewById(R.id.tv01);switch(item.getItemId()){case SAVE:tv.setText("保存按钮被点击");break;case RETURN_MENU:tv.setText("返回主菜单按钮被点击");break;case QUIT:tv.setText("退出按钮被点击");break;}return super.onOptionsItemSelected(item);} }