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);
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]
– mateusalxd
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();
– Leonardo Moura
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
– mateusalxd
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 Moura
@Leonardo, put this code in the question too, doing so is better for other people to understand your situation.
– Luídne
Leonardo, don’t just call the method
closeDrawer
passing hisListView
within theonItemClick
ofListener
ofListView
? It would be nice to follow the suggestion of Luídne and put the code you do to configure yourDrawerLayout
.– Wakim