package com.test.menu;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class OptionMenuActivity extends Activity {
private static final int ITEM1 = Menu.FIRST;
private static final int ITEM2 = Menu.FIRST + 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, ITEM1, 0, "功能1");
menu.add(0, ITEM2, 0, "功能2");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case ITEM1:
this.setTitle("功能1");
break;
case ITEM2:
this.setTitle("功能2");
break;
}
return true;
}
}
阅读(563) | 评论(0) | 转发(0) |