错误:未找到属性“srcCompat”的资源标识符

4

我在@drawable文件夹中使用复制+粘贴方式添加了两张图片,但是出现了错误。

 Error:(25) No resource identifier found for attribute 'srcCompat' in package 'com.example.francydarkcool.maps'

我已经添加了:
defaultConfig {
 vectorDrawables.useSupportLibrary = true;
 ...
}

在build.gradle文件中

还有:

    ImageView img1 = new ImageView(this);
    img1.setImageResource(R.drawable.cascada3);
    setContentView(img1);

    ImageView img2 = new ImageView(this);
    img2.setImageResource(R.drawable.cascada1);
    setContentView(img2);

在我的.java文件中。

这是我的activity_cascada_urlatoarea.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#479fc7"
    android:orientation="vertical"
    android:weightSum="480">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:weightSum="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="1"
            android:layout_weight="1"
            android:orientation="vertical" >


        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="227dp"
            app:srcCompat="@drawable/cascada3"
            android:id="@+id/imageView5"
            android:layout_weight="0.50"
            />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="200dp"
                app:srcCompat="@drawable/cascada1"
                android:id="@+id/imageView7"
                android:layout_weight="0.33"
                />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="68dp"
                android:orientation="horizontal"
                android:weightSum="1">

                <Button
                    android:text="Back"
                    android:layout_width="118dp"
                    android:layout_height="29dp"
                    android:id="@+id/button2"
                    android:background="@color/cast_mini_controller_main_background"
                    android:textSize="14sp"
                    android:textStyle="normal|bold"
                    android:textAlignment="center"
                    android:layout_marginTop="30dp"
                    android:onClick="backbttn"
                    android:layout_marginLeft="20dp"/>

                <Button
                    android:text="Next"
                    android:layout_width="118dp"
                    android:layout_height="29dp"
                    android:id="@+id/button8"
                    android:background="@color/cast_mini_controller_main_background"
                    android:textAlignment="center"
                    android:textStyle="normal|bold"
                    android:layout_weight="0.16"
                    android:layout_marginTop="30dp"
                    android:layout_marginLeft="110dp"
                    android:onClick="nextbttn"/>

            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

如果尝试更改

标签

xmlns:app="http://schemas.android.com/apk/res-auto"

使用

xmlns:app="http://schemas.android.com/apk/lib/com.app.chasebank"

我没有收到任何错误提示,但图片没有显示...

请帮忙解决。

1个回答

6

请确保在您的应用程序的 build.gradle 文件中,在dependency下使用最新版本的支持库(任何23.3+版本都可以工作)。

compile 'com.android.support:appcompat-v7:24.1.1'

然后清理并重新构建项目。


我按照你说的做了,但现在屏幕上只显示一张图片(你看不到下面的其他图片和按钮)。 - Andreea Mateescu
我解决了 :) 我从 .java 文件中删除了代码。 - Andreea Mateescu
很高兴能帮到你。你可以将此解决方案标记为正确答案,以供其他遇到类似问题的人参考。 - Arnav M.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接