Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Inject a Menu #1413

@KleinerHacker

Description

@KleinerHacker

If I want to use menu groups with id to change visibility of items between activity state changes I cannot use android annotations because I need the Menu instance to call method setGroupVisibile. There is a way to get the menu via android annotations like:

@EActivity
@OptionsMenu(R.menu.my_menu)
public class MyActivity extends Activity {
    @OptionMenu
    protected Menu menu;

   ....

   private void toggleState() {
      menu.setGroupVisibile(R.id.mnu_my_menu_grp_my_group1, false);
      menu.setGroupVisibile(R.id.mnu_my_menu_grp_my_group2, true);
   }
}

My current work arround is to override the onCreateOptionsMenu method:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        this.optionsMenu = menu;
        return super.onCreateOptionsMenu(menu);
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions