1 静态menu
2 动态menu
1) 生成menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/AddContact" android:title="@string/add_contact"/>
</menu>
2)重写方法
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_list, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.AddContact:
startActivity(new Intent(this, AddContactActivity.class));
return true;
}
return false;
}