android - 尝试绘制获得 AAPT 的图像:错误:“myimage”与属性 src (attr) 参考|颜色不兼容。错误信息
问题描述
我正在尝试绘制一个drawable,在我的资源文件行android:src =“myimage”中不断收到错误消息说AAPT:错误:'myimage'与属性src(attr)参考|颜色不兼容。错误信息
myimage.png 存储在 res/drawable 文件夹中。在用户界面中,我点击了 myimage 文件以确保它是有效的。我的照片出现在 ide 中。
我添加到资源文件以显示图像图像的代码
完整的资源文件
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#168BC34A" tools:context=".MainActivity">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:ignore="MissingConstraints">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/heading"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@android:color/holo_green_dark"
android:textSize="36sp"
android:textStyle="bold" />
<Button
android:id="@+id/startButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="#4CAF50"
android:text="@string/startButtonText"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<Button
android:id="@+id/stopButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="#4CAF50"
android:text="@string/stopButtonText"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="myimage"
android:contentDescription="@string/my_image_description"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
推荐阅读
- angular - 当 tsconfig.json 中的 compilerOptions.strict 为 true 时,嵌套 *ngIf="false" 会创建“错误 TS2532:对象可能是‘未定义’”
- laravel - Laravel 删除模型仅适用于本地环境
- java - 如何从 mFusedLocationProviderClient 获取结果(任务
没跑??) - node.js - Sequelize Model.create 与多对多关联
- python-3.x - 无法列出事件。资源 = 列表(事件['detail']['requestParameters']['evaluations'])[0]
- windows - 我可以运行 Windows IIS ACI 并连接到都在 Azure 中运行的 Oracle ACI 吗?
- c# - 如何在 c# 中从服务器位置获取 app.config 值
- laravel - Laravel Horizon:同一服务器上的多个实例相互干扰
- php - PHP AJAX 在下拉列表中选择某个值时显示一个值
- php - PHPUnit 不会自动检测目录中的文件