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

上一篇: invalidateOptionsMenu()在“重新启动”活动时不起作用

下一篇: 使用滑动选项卡功能在FragmentActivity中的一个Fragment中隐藏MenuItem