tos tos - 4 months ago 34
Android Question

Accessing application resources from the library project

My application depends on a library project.

The menu.xml file is within the application project.

All the java code is within the library project, including the menu handler code onOptionsItemSelected().

Is there a way to access the application resources from library project ? I'd like to write something like this, which is currently impossible, since menu items are not visible from the library:

if ( item.getItemId() ) {


Yes you can if you know the package name of your library.

You can do:

getResources().getIdentifier("res_name", "res_type", "com.library.package");

ex: would be:

getResources().getIdentifier("settings", "id", "com.library.package");