Hide Menu Navigation Drawer when choosing item

Asked

Viewed 1,134 times

4

I would like a help of how I can do when clicking on the Nvaigation Drawer item go to the specific Fragment, and in this Fragment I do not want to make available the Navigation Drawer for the user.

Free Market App Navigation Drawer Menu

When you click on a menu item it no longer appears the menu, only if you go back first

  • Welcome to [en.so], have you tried something? Already have some code? I advise you to take a look at this link: How to create a Minimum, Complete and Verifiable example, then you can get to know a little more of Sopt by doing a [tour]

  • Hello Matthew thanks for the attention, the example was passed in the image of the publication, I already have the Navigation Drawer ready. just when I call Fragment I want Drawer not to appear only if I go back to Main Activity where there is Menu... below example of how I call Fragment.. ExampleFragment fragment = new ExampleFragment();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();

  • I’m still not very familiar with Fragments, you can try to take a look at that link, see if he helps you with anything

  • Right my project I made based on that same example.. the doubt is just as I said after calling the Fragment stay on the screen only that Fragment and not appear the Navigation Drawer

  • @Leonardo, put this code in the question too, doing so is better for other people to understand your situation.

  • Leonardo, don’t just call the method closeDrawer passing his ListView within the onItemClick of Listener of ListView? It would be nice to follow the suggestion of Luídne and put the code you do to configure your DrawerLayout.

Show 1 more comment

2 answers

1

To hide the menu after the user select an item just you make the following code at the click of the item:

drawerLayout.closeDrawer(lst);

An example of how to do the whole process:

private DrawerLayout drawerLayout;
private ListView lst;
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayoutAdapter  drawerLayoutAdapter;

In your Activity onCreate make the following code:

mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer,
            R.string.drawer_open, R.string.drawer_close) {

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
              super.onDrawerClosed(view);
        }
    };

    mDrawerToggle.setDrawerIndicatorEnabled(true);
    drawerLayout.setDrawerListener(mDrawerToggle);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setIcon( new ColorDrawable(getResources().getColor(android.R.color.transparent))); 

And at the click of the item : drawerLayout.closeDrawer(lst);

0

Could disable Actionbar’s Fragment specific. Another thing I found that would be, in a way, a way not to appear the Drawer: the solution is to use the setVisible and call a method to restore the ActionBar.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.