3

I have more than one appcompat.v7 Toolbar in my layout.

Given this is the case the solution of "main" toolbars - setSupportActionBar() and then use the hooks in onCreateOptionsMenu() and onOptionsItemSelected() - isn't what I'm looking for.

The only way I've found so far is to cheat and put the Toolbar in a horizontal LinearLayout and "fake" action bar icons with ImageViews. There has to be a real way to do this but with the solution to "main" toolbars saturating searches I can't seem to find anything.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Graeme
  • 25,714
  • 24
  • 124
  • 186

1 Answers1

4

You can use this code to inflate a menu in your Toolbar:

mToolbar.inflateMenu(R.menu.menu_detail);

Then you can use it to attach a listener:

mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    //your code
                }    
            }
});
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841