Reputation: 177
I developing android app.I want to use navigation drawer in a fragment. I read some documantation and look at examples but all examples and documatation for activity.
I tried implement activity examples in my fragment but did not work.
i need your suggest and help.
Upvotes: 2
Views: 80
Reputation: 713
If you just want to hide the navigation drawer in other fragments, then you can follow this.
You can try to implement navigation drawer in an activity containing the fragments. And then, you can add the code below to the fragment where you don't want the navigation drawer to show up.
MainActivity.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
MainActivity.toggle.setDrawerIndicatorEnabled(false);
((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
Note: I implemented drawerLayout and toggle in my MainActivity which contains fragments and made them static so I was able to access them in a fragment.
Conversely, if you want to enable navigation drawer within the fragment, then add this code to the fragment:
MainActivity.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
MainActivity.toggle.setDrawerIndicatorEnabled(true);
((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Upvotes: 1