Search code examples
androidmenuandroid-menu

Android Get Properties from Menu Layout


I understand the proper usage of how to create a menu from a layout file.

My question is: Is it possible to get properties from a menu file without inflating it?


Solution

  • No, you have to inflate it, to get access to it. For example:

    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.my_menu, menu);
        View v = menu.findItem(R.id.item).getActionView(); // Get access to a View associated with example item
        return true;
    }