android - 如何使应用程序的矢量可绘制对象覆盖库的矢量可绘制对象?

标签 android gradle android-vectordrawable

我有一个库项目和一个应用程序项目。除了其他内容之外,库项目还包含一些 png 和一些矢量绘图。现在我可以通过给它相同的名称轻松覆盖应用程序项目中的 png 可绘制对象,并且它会正确显示。不过,这不适用于矢量可绘制对象:该应用始终显示库中定义的矢量可绘制对象,无论是在 Android 4 还是 5 上。该应用永远不会显示应用程序项目的矢量可绘制对象。

Google claims an application's resources always have priority over a library's resources :

Since the tools merge the resources of a library module with those of a dependent application module, a given resource ID might be defined in both modules. In this case, the tools select the resource from the application, or the library with highest priority, and discard the other resource. As you develop your applications, be aware that common resource IDs are likely to be defined in more than one project and will be merged, with the resource from the application or highest-priority library taking precedence.

但正如我所说,对于矢量可绘制对象,出于某种原因,情况正好相反。知道我可以做些什么来确保像普通可绘制对象和其他资源一样覆盖矢量可绘制对象吗?

更新:Resolved in support library v23.2 !现在无事可做:)

最佳答案

构建库项目时,VectorDrawable 为每个密度创建 PNG 文件,并将原始 VectorDrawable 放入 drawable-anydpi-v21 .

如果您将 VectorDrawable 放在您应用的 drawable-anydpi-v21 中,那么它将覆盖您的库项目中的可绘制对象。这似乎是一个错误,应该创建一个新问题(如果尚不存在的话)。


注意:这不会替换库中生成的 PNG 文件。您还需要将它们添加到您的应用中以覆盖它们。

关于android - 如何使应用程序的矢量可绘制对象覆盖库的矢量可绘制对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34608197/

相关文章:

java - 使用 android studio 更改 JNI 中的 Byte[] 值

android - 你能在 onDestroy() 中分离一个 fragment 吗?

java - Intellij外部库中所有类的“Cannot resolve symbol”

java - 在我的Minecraft服务器上,我的插件未加载

android - 我的 Android 应用程序已成功同步,但在运行该应用程序时出现错误任务 ':app:mergeDebugResources' 执行失败

android - 如何在矢量可绘制对象中设置 colors.xml 中的颜色代码?

Android VectorDrawable 作为复合绘图

Java---项目全局设置的正确使用和存储

php - Android从远程数据库获取数据

android - Espresso 不匹配具有许多字符的矢量绘图 - ImageDrawable(AppCompatResource)