gpt4 book ai didi

android - 错误 :error: 'drawable/delete.png' is incompatible with attribute android:background (attr) reference|color

转载 作者:行者123 更新时间:2023-11-29 23:18:20 27 4
gpt4 key购买 nike

当我尝试更改 Activity 的 XML 文件中的 android:background 时遇到了这个问题。

Information:Gradle tasks [:app:assembleDebug]
C:\Users\Valentin\AndroidStudioProjects\CedarRestaurants4\CedarRestaurants3\app\src\main\res\layout\activity_dynamic_view_ordering.xml
Error:error: 'drawable/delete' is incompatible with attribute android:background (attr) reference|color.
Error:'drawable/delete' is incompatible with attribute android:background (attr) reference|color.
Error:failed linking file resources.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Information:BUILD FAILED in 4s
Information:7 errors
Information:0 warnings
Information:See complete output in console

我的 Activity 的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<EditText
android:id="@+id/number_edit_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5" />

<Button
android:id="@+id/delete_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="drawable/delete.png"
android:onClick="onDelete" />
</LinearLayout>
<Button
android:id="@+id/add_field_button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#555"
android:layout_gravity="center"
android:onClick="onAddField"
android:textColor="#FFF"
android:text="New"
android:paddingLeft="5dp"/>
</LinearLayout>

<Button
android:id="@+id/placeOrderButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/parent_linear_layout"
android:layout_centerHorizontal="true"
android:layout_marginBottom="250sp"
android:text="@string/place_order"
android:textSize="32sp" />


</RelativeLayout>

我从教程项目中复制了 Activity 布局文件和 Activity ,并尝试将图像资源更改为更现代的东西。

我已经确保我的 delete.png 位于 /src/main/res/drawable 中,并且已经尝试在最后删除 .png,但没有运气。感谢您的帮助。

最佳答案

您忘记将 @ 添加到您的 drawable 并删除 extention。所以改变你的

android:background="drawable/delete.png"

这个

android:src="@drawable/delete"

关于android - 错误 :error: 'drawable/delete.png' is incompatible with attribute android:background (attr) reference|color,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54880183/

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