27

I am getting Error:(26) No resource identifier found for attribute 'srcCompat' in package 'learnapp.android.example.com.learnapp' when I try to run my app.I have just started learning android today.I have added a new activity and dint change anything in any xml files.

This is the exact error:

Documents/MyProjects/LearnApp/app/src/main/res/layout/activity_display_message.xml
Error:(26) No resource identifier found for attribute 'srcCompat' in package 'learnapp.android.example.com.learnapp'

Here is my activity_display_message.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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="learnapp.android.example.com.learnapp.DisplayMessageActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_display_message" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />

</LinearLayout>

I have already read similar questions and saw that either the line

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

or

app:srcCompat="@android:drawable/ic_dialog_email" />

was wrong in their case which is not in my case.

Incase it matters this activity's parent activity is MainActivity.java

user3425344
  • 3,357
  • 4
  • 20
  • 31
  • Can you try to set the drawable in you code `fab.setImageResource(R.drawable.ic_dialog_email);` – Harry Jul 02 '16 at 17:13

9 Answers9

35

I just changed

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

to

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

I saw the answer here

Community
  • 1
  • 1
user3425344
  • 3,357
  • 4
  • 20
  • 31
  • 7
    Don't do this. It changes the layout behaviour. If you try with a ScrollingActivity, it turns a mess – Zinc Nov 16 '16 at 09:35
14

change app:srcCompat="@android:drawable/ic_dialog_email" for

android:src="@android:drawable/ic_dialog_email"
tony gil
  • 9,424
  • 6
  • 76
  • 100
  • 1
    but the real question is WHY is Android Studio using "app:srcCompat"??? I'm getting tired of having to change this. – eric Nov 03 '16 at 00:10
  • 6
    Because app:srcCompat was added in AppCompat library 23.2, so if you have 23.1, it just don't exist. You can use android:src, but app:srcCompat supports vector images, so it's better – Zinc Nov 16 '16 at 09:37
12

Also happens when you have outdated versions of the support libraries.

I updated from:

compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'

to:

compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'

(those were the newest versions at the moment I wrote this)

and the error is gone.

carrizo
  • 689
  • 6
  • 15
12

You can also try

android:src = "@drawable/ic_dialog_email"

instead of

app:srcCompat="@android:drawable/ic_dialog_email"

I had the same error and this worked for me.

Bhaya Parikh
  • 145
  • 1
  • 4
2

Add this vectorDrawables.useSupportLibrary = true to your app level build.gradle

defaultConfig {
    ...
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    vectorDrawables.useSupportLibrary = true
}
Murli Prajapati
  • 8,833
  • 5
  • 38
  • 55
0

It looks like you just created a new project. So what fixed it for me was updating my build support tools, then creating a new project from scratch.

To update: Android Studio->Preferences...->Appearance & Behavior->System Settings->Android SDK->Android SDK Build-Tools->Check the box to update

TinyTheBrontosaurus
  • 4,010
  • 6
  • 21
  • 34
0

i got the similar issue.

my instructor try update API 22 to API 25, and it's work. maybe you could try on the same.

shiba
  • 1
  • 1
0

Happens if you start updating Android Studio and canceled the update midway complete the update process and everything should be back to normal

-1

I'm using the srcCompat api as follows.

<android.support.v7.widget.AppCompatImageView
      android:id="@+id/dashboard"
      android:layout_width="60dp"
      android:layout_height="60dp"
      srcCompat="@drawable/dash">

More info

Shree Harsha S
  • 665
  • 7
  • 14