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

后端 未结 2 1639
攒了一身酷
攒了一身酷 2021-01-01 17:07

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

相关标签:
2条回答
  • 2021-01-01 18:02

    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
    
    0 讨论(0)
  • 2021-01-01 18:08

    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!

    0 讨论(0)
提交回复
热议问题