Monday 15 April 2013

Switching between Android Navigation Drawer image and Up caret when using fragments -


When using the navigation drawer, Android Dev has recommended in the Actionbar "The screen that appears in the navigation drawer is actually Navigation Drawer Image "and" All other screens have traditional carats. "

For details see here:

I am using an activity to control multiple pieces And the Navigation Drawer Image provided at all levels Shit, and to get to work.

Set the driver indicator enabled (false) to hide the Navigation Drawer image when I create the low level fragments, Displayed

  lower level fragment loophreg = new lower level fragment (); // Disable the toggle menu and show the caret. Drawer toggle Sets driver indicator enabled (wrong); GetSupportFragmentManager (). BeginTransaction (). Replacement (R.id.frag_layout, low frog, "lowerfreag"). AddToBackStack (empty) .commit ();   

The problem is that when I navigate back to the top level pieces, the still shows up carats instead of the original navigation drawer image.


Solution

Tom's suggestion for me to suggest "refresh" the actionbars on top level pieces to display the Navigation Drawer image again The work done is what I did:

main activity

This activity controls all the pieces in the app.

When you create new pieces to replace the other, I set the set drawer to Sets driver indicator enabled (false) like this:

  Lower Level Fragment Loophreg = New Lower Level Fragment (); // Disable the toggle menu and show the caret. Drawer toggle Sets driver indicator enabled (wrong); GetSupportFragmentManager (). BeginTransaction (). Replacement (R.id.frag_layout, lowFrag) .addToBackStack (null) .commit (); In the override of  onBackpressed , I returned the drawer toggle from the  Sets driver indicator enabled (true)  to the top: Override public zeroes on   

/ P>

  @BackPressed () {super.onBackpressed (); // Turn on the navigation drawer image; // It is called the lower level fragments set driver indicator enabled (true)}   

in lower level fragments

I modified the code OnCreate and onOptionsItemSelected like this:

onCreate added setHasOptionsMenu (true) to the Options menu To enable, press & lt; setDisplayHomeAsUpEnabled (true) set to enable

  @override Creating a Public Zero (Bundle Saved Instance) {super .onCreate (savedInstanceState) to enable  ); // It is important to indicate that section I / I option menu setHasOptionsMenu (true) want to add items; // Update the action bar to show the carat / affordance getActivity () GetActionBar () SetDisplayHomeAsUpEnabled (true); }   

then onOptionsItem selected whenever pressed then it will be on backpress () Activity to move a level up in the hierarchy and display the navigation drawer image:

  @ Override Public Boolean On Option Item Select (menu item) {// select the item And deal with it (items .getItemId ()) {case android.r.id.home: // It is said that when the equalizer is pressed / carat up in the taskbar GetActivity () On backpress (); Back true; You have written, to apply a lower-level piece, you are changing the existing piece, as opposed to implementing a lower-level piece in a new activity.  

I would think that you have to apply the function manually again: When the user has pressed back to you the code that stack pops up (like activity :: onbackpressed override) Therefore, wherever you do this, you can enable the Sets Driver Indicator .

No comments:

Post a Comment