Saurav Jain
Saurav Jain

Reputation: 1

how to open close navigation drawer click on image view.i am not using action bar ?.

I am using linear layout in drawer layout.in linear layout has one image view i want to click the image view then open the navigation drawer but it is not done so i am posting one image so please give me suggestion

Upvotes: 0

Views: 668

Answers (4)

user5400869
user5400869

Reputation:

Use this: ((YourActivityWithDrawer)getActivity()).drawerLayout.openDrawer(your_drawer);

where:

  • YourActivityWithDrawer is your Activity containing drawer,

  • drawerLayout is your DrawerLayout object

  • your_drawer is the actual drawer object.

Upvotes: 0

sud
sud

Reputation: 505

there is one solution you can set the image as action bar app icon and you can open drawer on click of that image-

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

this line of code will Enable ActionBar app icon to behave as action to toggle navigation drawer

Upvotes: 0

Vivek Sinha
Vivek Sinha

Reputation: 1586

Do this in onClick of imageView:

if(drawer.isOpened()){ drawer.closeDrawer(your_drawer_view);}
else drawer.openDrawer(your_drawer_view);

Upvotes: 0

Jaydev Desai
Jaydev Desai

Reputation: 66

To open the NavigationDrawer use this :-

mDrawerLayout.openDrawer(Gravity.LEFT);

To close the NavigationDrawer use this :-

mDrawerLayout.closeDrawer(Gravity.LEFT);

Upvotes: 1

Related Questions