I want to do some operation when i click the menu (not a overflow menu) in Toolbar. How to detect the event of click menu or Opening DrawerLayout?
Asked
Active
Viewed 1,390 times
-1

Ramki Anba
- 754
- 1
- 10
- 21
-
Jayadeep Patel onOptionsItemSelected(MenuItem item) not called – Ramki Anba Jun 07 '17 at 13:10
-
1If you've set the `Toolbar` as the support `ActionBar`, then you can remove the `Toolbar` argument from the `ActionBarDrawerToggle` constructor call, and setup the `onOptionsItemSelected()` method like is shown here: https://stackoverflow.com/a/36570774. Inside the `if` block is where you'd put your additional code. – Mike M. Jun 07 '17 at 13:23
-
A simple fix would be to add an imageview into the toolbar with the hamburger icon as its src and then add an onclick listener to the imageview and perform you custom logic inside of the onclick method as well as programmatically toggle the navigation drawer. – cincy_anddeveloper Jun 07 '17 at 13:28
-
1Mike M Thank you – Ramki Anba Jun 07 '17 at 13:46
1 Answers
1
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// your stuff
}
});

IvBaranov
- 540
- 2
- 10
- 24