Hide MenuItem in one Fragment in FragmentActivity with swipe tabs functionality
I've a FragmentActivity with three swipe tabs. I've added a REFRESH Icon as MenuItem in actionbar and inflated that menu in FragmentActivity by overriding onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.live_stream_item, menu);
refreshMenuItem = (MenuItem) menu.getItem(0);
refreshMenuItem.setVisible(true);
return super.onCreateOptionsMenu(menu);
}
在片段的onCreate方法中设置setHasOptionsMenu(true)并覆盖片段中的onPrepareOptionsMenu()
,并设置相应菜单项的可见性。
@Override
void onPrepareOptionsMenu(Menu menu) {
// if nav drawer is opened, hide the action items
menu.findItem(R.id.xxx).setVisible(false);
menu.findItem(R.id.yyy).setVisible(false);
}
链接地址: http://www.djcxy.com/p/63918.html