【问题标题】:Android @drawable/logos.png error logos.png is incompatible with attribute android:resAndroid @drawable/logos.png 错误 logos.png 与属性 android:res 不兼容
【发布时间】:2018-08-27 12:56:16
【问题描述】:

我正要制作一个启动画面,我在 VSCode 而不是 android studio 中制作了它,因为我使用 Flutter 作为 SDK。我手动导入了图像(拖放)并更改了styles.xml和launch_background.xml中的一些东西(因为它是启动屏幕),我得到了这个错误

E:\Git\kene\android\app\src\main\res\drawable\launch_background.xml: AAPT: error: '@drawable\logos.png' is incompatible with attribute android:src (attr) reference|color.

E:\Git\kene\android\app\src\main\res\drawable\launch_background.xml:0: error: '@drawable\logos,png' is incompatible with attribute android:src (attr) reference|color.
error: failed linking file resources.
Failed to execute aapt
com.android.ide.common.process.ProcessException: Failed to execute aapt
at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:796)
at com.android.build.gradle.tasks.ProcessAndroidResources.invokeAaptForSplit(ProcessAndroidResources.java:551)
at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:285)
...

这是我的styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
    <!-- Show a splash screen on the activity. Automatically removed when
         Flutter draws its first frame -->
    <item name="android:windowBackground">@drawable/launch_background</item>
    <item name="android:windowFullscreen">true</item>
</style>
</resources>

这是我的launch_background.xml

 <?xml version="1.0" encoding="utf-8"?>
   <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />
    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable\logos.png" />
    </item>
    </layer-list>

我可以确保文件名正确并且文件位于 /src/main/res/drawable

【问题讨论】:

    标签: java android dart flutter


    【解决方案1】:

    从launch_background.xml中的文件名中删除.png,如下所示:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />
    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable\logos" />
    </item>
    </layer-list>
    

    【讨论】:

    • 也许您可以详细说明并显示代码 sn-p 以提供上下文?
    • 那里,我已经添加了相关部分。
    【解决方案2】:

    用正斜杠替换反斜杠 @drawable/logos.png 在launch_background.xml 位图android:src 属性中

    【讨论】:

    • 同样的结果,如果我更改了反斜杠,则错误变为未找到错误,并且我在互联网上发现了我仍然不太了解的资源链接。可能是因为我只是将图像拖放到可绘制文件夹中吗?
    • 检查图片是否存在于 resources/drawable 文件夹中,而不是 drawable-xxhdpi 或其他此类文件夹中
    • 是的,我可以确定
    • 输入command + shift+o 输入文件名粘贴路径
    猜你喜欢
    • 2018-06-20
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多