Artem Artem - 1 month ago 5
Android Question

How to use OptionMenu in Toolbar wich in Fragment view?

In my

Fragment
I want use
Toolbar
- no in
Activity
. How to use OptionMenu at this
Toolbar
?

Answer
toolbar = (Toolbar) fragmentView.findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.your_menu);
toolbar.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) { 
                switch (item.getItemId()){
                    //Do your magic
                }                    
                return true;
            }
        });
Comments