TabLayout custom menu
I have a TabLayout containing tabs as intents to activities. I want to set custom menu items for each tab, but the onCreateOptionsMenu version called is the Host's version. How can I ma开发者_Python百科ke the menu items created by each activity on its own.
If all you want is the sub-Activity's menu instead of the TabActivity's menu, then you just need it to stop propagation of onCreateOptionsMenu(). That is, normally you call "return super.onCreateOptionsMenu(menu);
" at the end, but if you just return true
instead then only that sub-Activity's menu should be displayed for any particular tab.
A call to
boolean result = super.onCreateOptionsMenu();
// do anything but don't change anything in the menu in case of the specific menu u want
return result;
Do the same with onPrepareOptionsMeny()
int cur = tabHost.getCurrentTab();
Log.i("current tab for asdasff", ""+cur);
tabHost.getTabWidget().getChildAt(cur).setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.context_menu, menu);
//createMenu(menu);
}
}
精彩评论