title: How to set visibility for an Actionbar menu item?
body: <p>I tried to hide item and group with below code it is not working, can someone please help me with this code. I tried for item and group both not working.</p>
  
  <pre><code>@Override
  public boolean onPrepareOptionsMenu(Menu menu) {
      super.onPrepareOptionsMenu(menu);
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.navigation_menu, menu);
      MenuItem shareItem = menu.findItem(R.id.login);
  
      // show the button when some condition is true
      if (true) {
          shareItem.setVisible(false);
      }
  
      menu.setGroupVisible(R.id.common_menu, false);
      return true;
  }
  </code></pre>