错误:没有属性'srcCompat'的资源标识符

And*_*scu 4 java android imageview android-studio

我在@drawable文件夹中使用Copy + Paste添加了2个图像,但是我收到错误

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

我已经添加:

defaultConfig {
 vectorDrawables.useSupportLibrary = true;
 ...
}
Run Code Online (Sandbox Code Playgroud)

在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);
Run Code Online (Sandbox Code Playgroud)

在我的.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>
Run Code Online (Sandbox Code Playgroud)

如果我试着改变

xmlns:app="http://schemas.android.com/apk/res-auto"
Run Code Online (Sandbox Code Playgroud)

xmlns:app="http://schemas.android.com/apk/lib/com.app.chasebank"
Run Code Online (Sandbox Code Playgroud)

我没有错误,但没有显示图像......

请帮忙.

Arn*_* M. 6

确保在您的应用程序的build.gradle文件中依赖 ...您正在使用最新版本的支持库(任何版本23.3+都可以).

compile 'com.android.support:appcompat-v7:24.1.1'
Run Code Online (Sandbox Code Playgroud)

然后清理并重建项目.