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?)
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" ).
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.
You can however, add all image files under /drawable and then access them programmatically via: int drawableID = context. getResources(). getIdentifier("drawableName", "drawable", getPackageName()); iv.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With