I wrote an android library for some UI utilities. I have a function that return ImageView. But, my problem is that I want that the resource of the drawable image, will be in the project that contains the library. I will explain...
I want that the ImageView will always take the drawable with the source name: R.drawable.ic_img_logo
(and only this name). This resource will not actually be in the library. But the project that contains the library will contains also drawable with the resource name R.drawable.ic_img_logo
.
I know that this thing works with id (of views), you can create file call ids.xml
and define some ids in the file that others can use them, and you will recognize them.
But how can I do this with drawables?
I found the answer. You need to create a file called drawables.xml
in the library. Then inside it write:
<resource>
<item name="ic_img_logo" type="drawable" />
</resource>
Its make fake resource R.drawable.ic_img_logo
. Then if the project that include the library have drawable called ic_img_logo
. The library be able to access to this drawable, because it will be the same resource.