Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
## Quick Hit: Android menus inside library projects

Summary: Android has issues if you have identically named menu resources in a library and consuming app project.

I recently discovered something to look out for if you are attempting to work with Activity toolbar/actionbar menus inside of a library. In my case, here is what I was doing:

  • Working with an activity inside of a library project.
  • Attempting to inflate a menu resource in the library Activity that was contained inside of the library project.
  • Open the library activity (actually an extended version of the activity) from the consuming Android app.

When I ran my consuming app activity, I was not seeing changes reflected to the menu in my app. This was really, really confusing.

It turns out that the problem was I had a menu resource xml in my consuming app with the exact same name as the library project menu. Even though the menu was referenced in the library activity with the library package resource, the consumnig app ended up picking its identically named version.

Changing the name of my library menu xml file fixed the issue right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment