简体   繁体   English

如何从Android的库项目中调用驻留在应用程序项目中的drawable?

[英]How to call a drawable which resides in app project from library project in android?

我想从android库项目中访问xml资源文件的app项目的应用程序drawable.Kindly指导我的代码段或指导。非常感谢。

You can define resources in the library and redefine them in the app1 and app2. 您可以在库中定义资源,然后在app1和app2中重新定义它们。

As long as the resources have the same filename, the ones defined in each app will override the ones from the lib. 只要资源具有相同的文件名,每个应用程序中定义的资源将覆盖lib中的资源。

You shouldn't do this. 你不应该这样做。 The whole point of a library project is that it is either self-contained or it is dependent on other library projects but not the main app project. 库项目的全部要点是它是独立的,还是依赖于其他库项目,而不是主应用程序项目。

You can have public methods in the library project that the app project can use to pass values but you shouldn't directly access variables from app project in the library project. 您可以在库项目中拥有公共方法,应用程序项目可以使用这些方法来传递值,但是您不应该直接从库项目中的应用程序项目中访问变量。

If you do this, the library project would be dependent on the app project and would no longer be modular, thus defeating the whole point of making it a library project in the first place. 如果执行此操作,则库项目将依赖于应用程序项目,而不再是模块化的,因此一开始就败于将其变成库项目的要点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM