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

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


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


The best way to determine which drawable resources are used between a library project (lib project) and an application project (app project) is down to design:

  1. By default, an app project's drawable resource will supersede the use of an identically named lib project's drawable resource. Therefore, the best way to ensure the lib project resource is used, is to remove the resource from the app project altogether.

  2. Another issue i came across is that if you want the app project resource to be used in preference, be sure that the drawable folder name in the app project is identical to the resource folder name in the library project. I.e. if your lib project resources live in drawable-mdpi, ensure the folder is called drawable-mdpi in the app project too!