You can do that as simple as in BaseActivity just don't forget to call super.onCreateOptionsMenu()
.
main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_help"
android:icon="@drawable/ic_action_help"
android:title="@string/action_help" />
</menu>
home.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_new"
android:icon="@drawable/ic_action_new"
android:title="@string/action_new" />
</menu>
In BaseActivity you are using base menu config main.xml
.
public class BaseActivity extends SherlockFragmentActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
In child activity you are using another config from home.xml
only with additional menu items, no duplicates. But don't forget to call super.onCreateOptionsMenu(menu)
with the same menu
instance to add elements from BaseActivity
(parent menu items would be added after child menu items if you call super
's method after inflate, and before otherwise).
public class HomeActivity extends BaseActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.home, menu);
return super.onCreateOptionsMenu(menu);
}
}