title: Switching between Android Navigation Drawer image and Up caret when using fragments
body: <p>When using the Navigation Drawer the Android devs are recommending that in the ActionBar "only those screens that are represented in the Navigation Drawer should actually have the Navigation Drawer image" and that "all other screens have the traditional up carat." </p>
  
  <p>See here for details: <a href="http://youtu.be/F5COhlbpIbY">http://youtu.be/F5COhlbpIbY</a></p>
  
  <p>I'm using one activity to control multiple levels of fragments and can get the Navigation Drawer image to display and function at all levels.</p>
  
  <p>When creating lower level fragments I can call the <code>ActionBarDrawerToggle</code> <code>setDrawerIndicatorEnabled(false)</code> to hide the Navigation Drawer image and have the Up caret displayed </p>
  
  <pre><code>LowerLevelFragment lowFrag = new LowerLevelFragment();
  
  //disable the toggle menu and show up carat
  theDrawerToggle.setDrawerIndicatorEnabled(false);
  getSupportFragmentManager().beginTransaction().replace(R.id.frag_layout, 
  lowFrag, "lowerFrag").addToBackStack(null).commit();
  </code></pre>
  
  <p>The problem I'm having is when I navigate back to the top level fragments the Up carat still shows instead of the original Navigation Drawer image. Any suggestions on how to "refresh" the ActionBar on the top level fragments to re-display the Navigation Drawer image? </p>
  
  <hr>
  
  <h2>Solution</h2>
  
  <p>Tom's suggestion worked for me.  Here’s what I did:</p>
  
  <h3>MainActivity</h3>
  
  <p>This activity controls all fragments in the app.</p>
  
  <p>When preparing new fragments to replace others, I set the DrawerToggle <code>setDrawerIndicatorEnabled(false)</code> like this:</p>
  
  <pre><code>LowerLevelFragment lowFrag = new LowerLevelFragment();
  
  //disable the toggle menu and show up carat
  theDrawerToggle.setDrawerIndicatorEnabled(false);
  getSupportFragmentManager().beginTransaction().replace(R.id.frag_layout,   
  lowFrag).addToBackStack(null).commit();
  </code></pre>
  
  <p>Next, in an override of <code>onBackPressed</code>, I reverted the above by setting the DrawerToggle to <code>setDrawerIndicatorEnabled(true)</code> like this:</p>
  
  <pre><code>@Override
  public void onBackPressed() {
      super.onBackPressed();
      // turn on the Navigation Drawer image; 
      // this is called in the LowerLevelFragments
      setDrawerIndicatorEnabled(true)
  }
  </code></pre>
  
  <hr>
  
  <h3>In the LowerLevelFragments</h3> 
  
  <p>In the fragments I modified <code>onCreate</code> and <code>onOptionsItemSelected</code> like this:</p>
  
  <p>In <code>onCreate</code> added <code>setHasOptionsMenu(true)</code> to enable configuring the options menu. Also set <code>setDisplayHomeAsUpEnabled(true)</code> to enable the <b>&lt;</b> in the actionbar:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      // needed to indicate that the fragment would 
      // like to add items to the Options Menu        
      setHasOptionsMenu(true);    
      // update the actionbar to show the up carat/affordance 
      getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
  }
  </code></pre>
  
  <p>Then in <code>onOptionsItemSelected</code> whenever the <b>&lt;</b> is pressed it calls the <code>onBackPressed()</code> from the activity to move up one level in the hierarchy and display the Navigation Drawer Image:</p>
  
  <pre><code>@Override
  public boolean onOptionsItemSelected(MenuItem item) {   
      // Get item selected and deal with it
      switch (item.getItemId()) {
          case android.R.id.home:
              //called when the up affordance/carat in actionbar is pressed
              getActivity().onBackPressed();
              return true;
          … 
      }
  </code></pre>