title: How to hide OptionsMenu on NavigationDrawer using Fragments?
body: <p>I am creating android application and I'm trying to respect as much as possible the latest Android usability standards. In particular, I am preparing the user interface using the navigation drawer, and I'm trying to ensure compatibility with 2.1+ Android versions. To appreciate the problem, the project consists of:</p>
  
  <ul>
  <li>A main activity;</li>
  <li>A navigation drawer;</li>
  <li>Four fragments (with their associated layouts).</li>
  </ul>
  
  <p>The problem I'm experiencing occurs when opening the navigation drawer: although each <code>Fragment</code> has its specific menu, when I open the navigation drawer it is added to the nav drawer menu. I tried in several ways (<code>invalidateOptionMenu()</code>, <code>menu.clear()</code>, manipulating functions <code>isDrawerOpen()</code> and <code>isDrawerClose()</code> and more), but I cannot remove the <code>Fragment</code>'s menu when opening the navigationdrawer.</p>
  
  <p>These are some snippets of my code, much of it generated by Android Studio, the IDE I'm using:</p>
  
  <p>In main activity:</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      if (!mNavigationDrawerFragment.isDrawerOpen()) {
          // Only show items in the action bar relevant to this screen
          // if the drawer is not showing. Otherwise, let the drawer
          // decide what to show in the action bar.
          getMenuInflater().inflate(R.menu.global, menu);
          restoreActionBar();
          return true;
      }
      return super.onCreateOptionsMenu(menu);
  }
  </code></pre>
  
  <p>where "global" is a simple menu with a classical "ic_action_overflow".</p>
  
  <p>And in my fragments I've:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setHasOptionsMenu(true);
  }
  
  @Override
  public void onPrepareOptionsMenu(Menu menu) {
      super.onPrepareOptionsMenu(menu);
  }
  
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      super.onCreateOptionsMenu(menu, inflater);
      inflater.inflate(R.menu.fragment1, menu);
  }
  </code></pre>
  
  <p>(It's the same of the other <code>Fragment</code>s).</p>
  
  <p>Someone can give me some advice on how to act?</p>