7

I have a Activity A, a ListFragment P and 2 Fragments Q and R.

When the app is launched, A is created, which loads P. Based on what user clicks, it is replaced by Q or R.

Now by referencing this tutorial, I have implemented a Navigation Drawer which shows certain items to the user. However, since I have implemented the Navigation Drawer in the Activity, it shows for all the Fragments. I want it to be only available to P.

(Very much similar to Googles Gmail app. When the user is on the main screen - the drawer is present. When user taps to open an email, the drawer changes to back button)

I am not sure how to translate the above code. Any help is appreciated.

rgamber
  • 5,749
  • 10
  • 55
  • 99
  • are you sure it's not another activity? I think you can anyway make a framelayout as the activity layout and then replace the drawerfragment at all – sherpya Mar 13 '14 at 06:38
  • If you mean implement the drawer as a fragment and replace it, then that is an interesting suggestion that I did not think of. Will try and get back to you! – rgamber Mar 13 '14 at 06:52
  • `DrawerLayout` is a `Layout` I think you can just inflate it into a fragment – sherpya Mar 13 '14 at 06:55
  • Well, I am using a list fragment which uses the default android list layout. But I will try with a custom layout. Though for the drawer, I am guessing that I will still need the activity context. So not sure how it can be specific to that fragment. – rgamber Mar 13 '14 at 07:05
  • if you need to customize `ListFragment` layout you can follow my post http://stackoverflow.com/questions/11770773/listfragment-layout-from-xml/12145683#12145683 – sherpya Mar 13 '14 at 07:10
  • @sherpya, the solution to this was really simple :) I have added my answer if you are curious! – rgamber Mar 19 '14 at 16:45

2 Answers2

8

I solved this issue by simply overriding the up carat behavior by calling the mDrawerToggle.setDrawerIndicatorEnabled(enable) and passing the boolean enable or disable as needed.

(The fragments where I didn't want the drawer to show called this method with false and where I wanted the drawer to be shown called this method with true. I put the call inside the onResume() of the respective fragment for obvious reasons.)

This works exactly like I want, and I did not have to change the design of my project :).

rgamber
  • 5,749
  • 10
  • 55
  • 99
0

What you can do is create a new FragmanetActivity S and replace Q and R accordingly. If you are app is for Android 3.0 lower user ActionBarActivity create a actionbar and set its setDisplayHomeAsUpEnabled(true). As the new FragmentActivity will have new layout there will be no NavigationDrawer.

Atif Farrukh
  • 2,219
  • 2
  • 25
  • 47
  • This is the obvious solution, yes. But I want to see if there is a way of doing it using just Fragments, and avoid introducing unnecessary Activities. :) – rgamber Mar 11 '14 at 06:29
  • @rgamber AFAIK I don't think its possible as the main `layout` remains same when `Fragment` is replace in the `FrameLayout`. Just the contents of the `FrameLayout` are changing whenever a `Fragment` is replaced and `NavigationDrawer` is attached to the main layout so it will always be above the `FrameLayout`. – Atif Farrukh Mar 11 '14 at 06:34