Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?)

like image 886
Vijay Krishna Avatar asked Jun 05 '11 06:06

Vijay Krishna


People also ask

How do you reference a drawable Android?

Note: A color resource can also be used as a drawable in XML. For example, when creating a state list drawable, you can reference a color resource for the android:drawable attribute ( android:drawable="@color/green" ).

How do I import Drawables?

Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import. Figure 3: Select Import Drawables from the dropdown menu.

How do I get to the drawable folder on Android?

You can however, add all image files under /drawable and then access them programmatically via: int drawableID = context. getResources(). getIdentifier("drawableName", "drawable", getPackageName()); iv.


1 Answers

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
like image 128
Alex Gitelman Avatar answered Oct 28 '22 12:10

Alex Gitelman