Navigation Drawer and with Activity in Android - android

I am trying out the navigation drawer (slide menu) given in this tutorial.
The difference with above link and mine is that instead of calling fragments I am trying to call the activity. When the app opens I am not able to see the Navigation drawer menu I can see only the action bar with HOME activity opened.
Here is the code that I changed: (Is it necessary to have a fragment or can I use activity for my first screen in Navigation Drawer?)
mTitle = mDrawerTitle = getTitle();
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
navDrawerItems = new ArrayList<NavDrawerItem>();
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(1, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(2, -1),true, "200"));
navMenuIcons.recycle();
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
adapter = new NavDrawerListAdapter(getApplicationContext(), navDrawerItems);
mDrawerList.setAdapter(adapter);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.drawer,
R.string.drawer_open,
R.string.drawer_close
)
{
public void onDrawerClosed(View view)
{
getActionBar().setTitle(mTitle);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView)
{
getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null)
{
displayView(0);
}
}
private class SlideMenuClickListener implements
ListView.OnItemClickListener
{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
displayView(position);
}
}
private void displayView(int position)
{
switch (position)
{
case 0:
//fragment = new HomeFragment();
Intent intent = new Intent(this, Home.class);
startActivity(intent);
return;
case 1:
//fragment = new FindPeopleFragment();
Intent intent1 = new Intent(this, Profile.class);
startActivity(intent1);
break;
case 2:
//fragment = new PhotosFragment();
Intent intent2 = new Intent(this, Details.class);
startActivity(intent2);
break;
default:
break;
}
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
How do I fix this to show Navigation drawer on my Home Activity?
Update:
I even tried the following option given in this link:
How can I call one of my activity using navigation drawer ? but I am still not getting the navigation slide menu.

You can't do that...
Navigation drawer is a layout from an activity and you cant show an activity inside another activity, you need to use a fragments for this!
An activity is a screen, you cant show a screen inside another screen, but a fragment may be a component of a screen, and you can inflate a fragment inside a container of an activity and then show to the user.
if you wan't do this, you can create a abstract activity and inherit, but you will not have a a activity in a fragment, you will have a multiple activities with each one with your own navigation drawer.

If you look at the sample documentation for Android Navigation drawer, it is explicitely defined to use fragments instead of activities to load different 'pages' from the navigation bar. As the app lifecycle for Android goes, fragments are easier to load and produce less impact on the Android system. they can also be easily set into the background and be replaced by other different fragments.
Having said that, your best approach would be to convert your activities into fragments and use them to load the different pages you need in your app. It is not such a difficult task, and I will show you how:
Change all activities to fragments
public class nameOfFragment extends Fragment { }
Use the onCreateView method instead of onCreate
public View onCreateView() {
View view = inflater.inflate(R.layout.activity_main, container, false);
//any other elements in that view need to be included here in this manner.
Button rate = (Button) rootView.findViewById(R.id.rate);
return view;
}
These changes should be enough to change your activities into fragments.
You need to do the same for all fragments which are accessed through your navigation bar.
Please post your code for the activities you are using if you need any further help.
Hope this helps :)

You've got the code to build and display a navigation bar right? Put your code above into a base activity class. Every activity that you want to access the navigation bar from should then inherit from that base class.
Google's IO 2014 app does the same thing, take a look at their source here.
When you do this, you will need to find a way to maintain the drawer's state as you transition to the next activity. I'm not sure how to do that, but you'll probably find the answer in the source code for the IO app.

If you have to have single instance of drawer, then you have to go by fragments.
If you have no choice to go other than with activities, define a base class for all your activites(say BaseActivity). And in BaseActivity - you can do the necessary coding to integrate drawer. Each activity extending BaseActivity will now show up drawer menu (but the instances will be different)

Now you need to use the toolbar. Android has made appcompat library to introduce material design in older versions of android as well. You need to use compile dependency of appcompat.
Change the style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
Then we will choose to have no old action bar. After then we make a contract between navigation drawer and toolbar. So we need not to use old actionbar now.
You can refer the code below:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff6d7fe2"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
></android.support.v7.widget.Toolbar>

Related

How to prevent NavigationDrawer from being opened by gesture, but allow from hamburger icon in Support Design Library 23.1.1.1

I have a ViewPager where pages contain charting views which react to sliding movements. Due to this i resorted to changing the page by sliding from the edge of the screen. But that leaves me with the problem that this is also the gesture to open the NavigationDrawer.
Until now i used the following code to achieve this:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(GetLayoutId());
Toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
if (Toolbar != null)
{
// set this flag so the colors colorPrimaryDark and android:statusBarColor have an effect
// setting android:statusBarColor to transparent causes the drawer to be dran underneath a translucent status bar
Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
// make the toolbar the replacement of the action bar
SetSupportActionBar(Toolbar);
}
// add the hamburger icon
m_DrawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
var actionBarDrawerToggle = new ActionBarDrawerToggle(this, m_DrawerLayout, Toolbar, Resource.String.empty, Resource.String.empty);
m_DrawerLayout.AddDrawerListener(actionBarDrawerToggle);
// make sure the drawer can't be opened by swiping, to do this we set the lock mode to closed
// but if we just do this, it can't be closed by swiping either, so set the lock mode to unlocked when the drawer is opened, and locked again when it's closed
m_DrawerLayout.DrawerOpened += (object sender, DrawerLayout.DrawerOpenedEventArgs e) =>
{
m_DrawerLayout.SetDrawerLockMode(DrawerLayout.LockModeUnlocked);
};
m_DrawerLayout.DrawerClosed += (object sender, DrawerLayout.DrawerClosedEventArgs e) =>
{
m_DrawerLayout.SetDrawerLockMode(DrawerLayout.LockModeLockedClosed);
};
m_DrawerLayout.SetDrawerLockMode(DrawerLayout.LockModeLockedClosed);
//calling sync state is necessay or else the hamburger icon wont show up
actionBarDrawerToggle.SyncState();
}
It worked as intended, until i updated to the Android Support Design Library 23.1.1.1, now setting the lock mode to closed also prevents the menu from being opened by tapping on the hamburger icon.
Looking at the source code for the latest version of the ActionBarDrawerToggle class, this does indeed seem to be the new intended behavior. It's toggle() method now looks like this:
private void toggle() {
int drawerLockMode = mDrawerLayout.getDrawerLockMode(GravityCompat.START);
if (mDrawerLayout.isDrawerVisible(GravityCompat.START)
&& (drawerLockMode != DrawerLayout.LOCK_MODE_LOCKED_OPEN)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
}
else if (drawerLockMode != DrawerLayout.LOCK_MODE_LOCKED_CLOSED) {
mDrawerLayout.openDrawer(GravityCompat.START);
}
}
whereas it previously just checked the drawer's opened/closed state.
This is unfortunate, since it will now take a workaround to achieve the old behavior. Perhaps the simplest thing to do is just to revert to an older version of the support library. However, if you want to keep the newest version, one possible solution is as follows.
First remove the Toolbar argument from the ActionBarDrawerToggle constructor call.
actionBarDrawerToggle = new ActionBarDrawerToggle(this,
m_DrawerLayout,
Resource.String.empty,
Resource.String.empty);
This will cause the Activity's OnOptionsItemSelected() method to fire upon clicking the toggle, since you've set the Toolbar as the support ActionBar. We will also need to call SupportActionBar.SetDisplayHomeAsUpEnabled(true) to actually show the toggle, since the ActionBarDrawerToggle class interacts somewhat differently with an ActionBar than it does with a Toolbar, with respect to their child Views.
In the Activity's OnOptionsItemSelected() method, we then simply unlock the drawer before calling the toggle's own OnOptionsItemSelected() method, which handles the opening and closing of the drawer.
public override bool OnOptionsItemSelected (IMenuItem item)
{
switch (item.ItemId)
{
case Android.Resource.Id.Home:
m_DrawerLayout.SetDrawerLockMode(DrawerLayout.LockModeUnlocked);
actionBarDrawerToggle.OnOptionsItemSelected(item);
return true;
...
}
...
}
Your actionBarDrawerToggle will need to be a field of your Activity, and you can remove the DrawerOpened handler.

How to programatically disable and enable items every time an Android NavigationView is displayed

I am moving some menu items from the options menu to the navigation menu. My app uses a NavigationView that is populated by a menu as described at https://developer.android.com/reference/android/support/design/widget/NavigationView.html
One of the items calls webView.goBack() on the WebView in the main activity. When it was placed in the options menu, it was only enabled if webView.canGoBack(). Otherwise, it was disabled (grayed out). To accomplish this, onPrepareOptionsMenu() included the command:
back.setEnabled(webView.canGoBack());
As onPrepareOptionsMenu() is called every time the options menu is about to be displayed, this would update the status of the menu item to correctly reflect the state of the WebView.
However, I have not been able to replicate this behavior with the NavigationView. Is there a method or class similar to onPrepareOptionsMenu() that is called each time the NavigationView is prepared?
PS. Other people who have addressed similar questions have always referred to using a ListView, which was an older method of populating a navigation drawer. This question specifically relates to using a NavigationView with a menu.
The answer to this question is to add a DrawerListener and override onDrawerStateChanged.
// Create the navigation drawer.
drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
// The `DrawerTitle` identifies the drawer in accessibility mode.
drawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.navigation_drawer));
// Listen for touches on the navigation menu.
final NavigationView navigationView = (NavigationView) findViewById(R.id.navigationView);
navigationView.setNavigationItemSelectedListener(this);
// Get handles for `navigationMenu` and the back and forward menu items. The menu is zero-based, so item 1 and 2 and the second and third items in the menu.
final Menu navigationMenu = navigationView.getMenu();
final MenuItem navigationBackMenuItem = navigationMenu.getItem(1);
final MenuItem navigationForwardMenuItem = navigationMenu.getItem(2);
// The `DrawerListener` allows us to update the Navigation Menu.
drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
#Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
#Override
public void onDrawerOpened(View drawerView) {
}
#Override
public void onDrawerClosed(View drawerView) {
}
#Override
public void onDrawerStateChanged(int newState) {
// Update the back and forward menu items every time the drawer opens.
navigationBackMenuItem.setEnabled(webView.canGoBack());
navigationForwardMenuItem.setEnabled(webView.canGoForward());
}
});
NavigationView exposes its underlying Menu with getMenu(). You can use that to find menu items and make changes to them.

Sharing NavigationView with all the Activities?

How do we share Drawer with all the activities?
In the lister: onNavigationItemSelected of setNavigationItemSelectedListener we can get the id and navigate to it. What I am looking for is something like this:
private void initDrawerLayout() {
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navView = (NavigationView) findViewById(R.id.navigation_view);
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
Intent intent;
int id = menuItem.getItemId();
switch(id) {
case R.id.home:
case R.id.drawer_home:
// call activity instead of adding/replacing fragment
return true;
case R.id.drawer_gallery:
// call activity instead of adding/replacing fragment
intent = new Intent(MainActivity.this, GalleryActivity.class);
startActivity(intent);
return true;
case R.id.drawer_about:
// call activity instead of adding/replacing fragment
intent = new Intent(MainActivity.this, AboutActivity.class);
startActivity(intent);
return true;
...
}
...
I know I can make all the menuItems add/replace Fragment, but then handling fragments and memory management is a big pain.
Instead I want each menuItem select/click to invoke Activity. i.e. each MainMenuItem to have Activity and those will hold fragments with complex layouts.
All I want to do is have each main menu item be an Activity instead of a
Fragment.
And all these activities can share same DrawerNavigation.
Is this the recommended way? Or do we always add Fragments for NavigationDrawer item clicks??
Should I add NavigationView to BaseActivity and then extend all activities from there??
Following this new guide about Support Design lib
I found the answer using this SO answer
Extending is the right way. Just override setContentView in the right way...
I am a bit confused here as well. After finding very little information on this I tried to extend my subclass
public class NewActivity extends MainActivity{
...
}
However, this alone didn't do anything. the MainActivity has a fully functioning NavigationView that will navigate to each activity..Only thing that is left is sharing it with each activity.

Why is my Navigation drawer menu opens other activities automatically without clicking the buttons?

What i have is left navigation menu that i have made using navigation drawer and i want it's button to open activities instead of fragments .. but the weird thing is that when the main activity opens which has the menu it open the second activity direct without displaying the main activity .. here is my code :
private void displayView(int position) {
Intent intent = null;
switch (position) {
case 0:
intent = new Intent(MainActivity.this, Gallery.class);
break;
....
if(intent != null) {
mDrawerLayout.closeDrawer(mDrawerList);
setTitle(navMenuTitles[position]);
startActivity(intent);
}
else {
// error in creating activity
Log.e("MainActivity", "Error in creating Activity");
}
}
And i call it from here :
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
// on first time display view for first nav item
displayView(0);
}
}
So why this is happening? can anyone help me?
In generally, the navigation drawer is initialized with some code when the activity starts(to show one of the items/do something). If, when you start the activity holding this navigation drawer, you immediately go the one of the activities pointed by the navigation drawer items then you need to check your code to see if you're not by any chance calling the displayView() method when the activity starts(which will start the other activity).
Have you implemented a ListView inside of your Navigation Drawer? I had the same problem and it turns out that when I was setting my adapter for the ListView I was using
divListView.setAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item__activated_1,
android.R.id.text1,
divisionAda));
The ListView was "activated" making it gain focus and displaying it on top of the activity. I remedied the problem by removing the "activated".
So now my setting my adapter looks like this:
divListView.setAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1,
android.R.id.text1,
divisionAda));

Disabling navigation drawer, toggling home-button/up-indicator in fragments

The setup
I have an activity whose contentView is an instance of a DrawerLayout, which has a navigation drawer with a drawer indicator displayed in the action bar. The activity contains a Fragment, let's call it ListFragment, which contains a list of options. When an option is clicked, I replace the ListFragment with a DetailFragment.
At this point, I would like to display an "up" navigation option instead of the navigation drawer indicator. I'm able to display the "up" icon if I disable the drawer indicator by calling mDrawerToggle.setDrawerIndicatorEnabled(false), but this only removes the drawer icon--it does not remove the functionality--that is, when I click the caret, the navigation drawer is still opened.
Additionally, in these subviews, I would like to disable the opening of the drawer by dragging from the edge of the screen. I have tried doing this by calling setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) but it doesn't seem to have disabled this functionality.
I have tried extending the ActionBarDrawerToggle class to prevent opening the drawer when the indicator is clicked--however, all that happens is that the overriding action (the "up" navigation) is performed, but the drawer still opens.
I have also implemented the steps in Switching between Android Navigation Drawer image and Up caret when using fragments . It works insofar as displaying the caret goes, but despite overriding the up button functionality, the menu still opens (the app does navigate back--it just also opens the drawer).
Question
So, long story short: is there any (preferably clean and elegant, but at this point I'll go with hacky) way to achieve these things when my layout root is a DrawerLayout:
Replace the drawer indicator with an "up" caret (tentatively doable via mDrawerToggle.setDrawerIndicatorEnabled(false))
Prevent the drawer from opening when the caret is clicked, and instead override with my own "up" functionality
Prevent the drawer from opening when I drag from the edge of the screen.
Edit
All right, it looks like if I both override ActionBarDrawerToggle AND onOptionsItemSelected, the menu does not open when I click the caret. But it still opens if I drag from the edge. Help!
Short Code
public void setDrawerState(boolean isEnabled) {
if ( isEnabled ) {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
drawerToggle.onDrawerStateChanged(DrawerLayout.LOCK_MODE_UNLOCKED);
drawerToggle.setDrawerIndicatorEnabled(true);
drawerToggle.syncState();
}
else {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
drawerToggle.onDrawerStateChanged(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
drawerToggle.setDrawerIndicatorEnabled(false);
drawerToggle.syncState();
}
}
This is only part of the solution that I arrived at, but it was quite hard to figure out this bug, so I'm leaving this here for posterity's sake.
This how I was defining the ListView for my navigation drawer:
<ListView
android:id="#+id/listview_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start|bottom"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
Even after calling setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) I was still able to slide the drawer open.
However, after changing the layout_gravity to "start" this problem seems to be resolved.
I was able to reproduce this issue in a sample, navigation-drawer-only app, so it does appear to be a reproducible issue not unique to my situation.
Building on sonida's answer. After calling setDrawerIndicatorEnabled(false), onNavigateUp wasn't being called still. So, I just created a new onClickListener that called it:
public void setDrawerState(boolean isEnabled) {
if ( isEnabled ) {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
drawerToggle.setDrawerIndicatorEnabled(true);
drawerToggle.syncState();
}
else {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
drawerToggle.setDrawerIndicatorEnabled(false);
drawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onSupportNavigateUp();
}
});
drawerToggle.syncState();
}
}
also I think
drawerToggle.onDrawerStateChanged(DrawerLayout.LOCK_MODE_UNLOCKED);
has been depreciated, but it works fine without it.
You need to disable swipe and disable the actionbar home button:
Use the below code that builds on the code already given to disable swipe
public void setDrawerState(boolean isEnabled) {
if ( isEnabled ) {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
mDrawerToggle.onDrawerStateChanged(DrawerLayout.LOCK_MODE_UNLOCKED);
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerToggle.syncState();
getActivity().getActionBar().setHomeButtonEnabled(true);
}
else {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerToggle.onDrawerStateChanged(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerToggle.syncState();
getActivity().getActionBar().setHomeButtonEnabled(false);
}
}
Building on answer by #sonida And after using the tweaks given by #luca992 and #jai.
I tried above suggested codes But the "up" or "Back" arrow in left side of action bar was just not showing up in my app. But luckily I was able to fix that.
I had to add this extra line of code in setNavigationDrawerState() [Ref: android.support.v7.app.ActionBarDrawerToggle.setHomeAsUpIndicator ]
toggle.setHomeAsUpIndicator(R.drawable.ic_keyboard_backspace_white_24dp);
I downloaded the drawable: ic_keyboard_backspace_white_24dp from Material.io
Here is the complete code:
MainActivity.java -> onCreate()
DrawerLayout drawer;
ActionBarDrawerToggle toggle;
#Override
protected void onCreate(Bundle savedInstanceState) {
// Start: Code automatically generated by Android Studio
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
// End: Code automatically generated by Android Studio
// I had to add this listener as the "back" arrow was totally unresponsive
// Thanks to #luca992
toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
// Start: Code automatically generated by Android Studio
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
// End: Code automatically generated by Android Studio
// More custom code for other stuff
// ...
}
MainActivity.java -> setNavigationDrawerState()
public void setNavigationDrawerState(boolean isEnabled) {
if ( isEnabled ) {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
toggle.setDrawerIndicatorEnabled(true);
toggle.syncState();
}
else {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
toggle.setDrawerIndicatorEnabled(false);
// the extra line of code goes here
toggle.setHomeAsUpIndicator(R.drawable.ic_keyboard_backspace_white_24dp);
toggle.syncState();
}
MainActivity.java -> onBackPressed()
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else if(getSupportFragmentManager().getBackStackEntryCount() > 0){
getSupportFragmentManager().popBackStack();
}else {
super.onBackPressed();
}
}
MainActivity.java -> startFragment() [dummy function for example]
public void startFragment(){
MyFrag myFrag = new MyFrag();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.frag_container ,myFrag)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
}
MyFrag.java --> onViewCreated()
#Override
public void onViewCreated (View view, Bundle savedInstanceState){
super.onViewCreated(view, savedInstanceState);
// Say, using an implemented interface Make call to MainActivitiy's setNavigationDrawerState() passing false
// setNavigationDrawerState(false)
// ...
}
MyFrag.java --> onDestroyView()
#Override
public void onDestroyView(){
// Say, using an implemented interface Make call to MainActivitiy's setNavigationDrawerState() passing true
// setNavigationDrawerState(true)
super.onDestroyView();
}

Categories

Resources