gpt4 book ai didi

android - 无法在应用程序中使用 png 资源覆盖库的 xml 资源?

转载 作者:IT老高 更新时间:2023-10-28 23:12:31 24 4
gpt4 key购买 nike

我有一个 Android 库 MyLib,其中包含我的应用所需的一切(针对 Android 2.2)。这个库有一个 XML 资源:

drawable/main_background.xml

在我的应用程序 MyApp 项目中,我引用了 MyLib。在这里,我想覆盖特定资源(即品牌)。所以我在 MyApp 中添加了背景图片:

drawable/main_background.png

Eclipse 一直给我这个错误:

[com.mycom.mylib.myapp] res\drawable\main_background.xml:0: error: Resource entry main_background is already defined.
[com.mycom.mylib.myapp] res\drawable\main_background.png:0: Originally defined here.

如何覆盖库项目中的资源?

最佳答案

您不能简单地使用 Android SDK 中具有不同扩展名的文件覆盖资源 ID(它是您要覆盖的资源 ID,而不是实际文件)。但是,您可以通过放入具有相同名称 (main_background.xml) 的项目 xml 文件并以正确的方式填充它以显示您的新文件 (main_background.png),您需要提前重命名。您需要的所有语法都在这里描述:

http://developer.android.com/guide/topics/resources/drawable-resource.html

,在你的情况下,它可能很简单(假设你把它作为 main_background.xml 放在你的非库项目中,并且你有你的新 png 作为 main_background_new.png):

<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/main_background_new" />

通过上述解决方案,您可以从您的项目中引用 @drawable/main_background,它应该使用该项目中包含的文件,而不是库文件。

关于android - 无法在应用程序中使用 png 资源覆盖库的 xml 资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10055926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com