How to reference a drawable from a library project into a main project's layout in android?

Vijay Krishna picture Vijay Krishna · Jun 5, 2011 · Viewed 8.9k times · Source

I have a android library project and reusable drawable resources in it.
Lets say package name is: com.vijay.mylib;

Then i have a main project and it uses the above library project.
Lets say its package name is:com.vijay.myproject.

Consider that I have linked library project with my main project correctly.

In my main project i have a layout called main.xml. I want to use some drawable rom library project in main.xml. How can i do it in xml?
Refering in normal way like "@drawable/myImage" didn't work for me. The referece chooser windows shows me the drawables only from main project. Not from library project.

(Note : Both projects have different package for R.java. Does it has do anything with this?)

Answer

Alex Gitelman picture Alex Gitelman · Jun 5, 2011

You probably would need to add your own uri for library and use it to refer to drawable.

xmlns:vijay="http://schemas.android.com/apk/res/com.vijay.mylib"

Then you should be able to access drawable using

@vijay:drawable/myImage