错误:(27)未找到属性“srcCompat”中包“com.example.jaisonjoseph.newsclient”资源标识符

问题描述:

enter image description here 我添加了一个ImageButtonCardView,当我加入app:srcComapatImageButton。我发现了一个错误,如下面:错误:(27)未找到属性“srcCompat”中包“com.example.jaisonjoseph.newsclient”资源标识符

Error:(27) No resource identifier found for attribute 'srcCompat' in package 'com.example.jaisonjoseph.newsclient'

这里是我的content_main.xml布局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.example.jaisonjoseph.newsclient.MainActivity" 
    tools:showIn="@layout/app_bar_main" 
    style="@style/Base.Widget.AppCompat.ButtonBar" 
    android:background="#ffffff"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/card_view" 
     android:layout_width="350dp" 
     android:layout_height="150dp" 
     app:cardCornerRadius="6dp" 
     android:background="#f6f6f6" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true"> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      app:srcCompat="@drawable/daily" 
      android:id="@+id/imageButton3" 
      android:src="@drawable/daily" /> 
    </android.support.v7.widget.CardView> 
</RelativeLayout> 
+0

删除'RelativeLayout'中的'xmlns:app2'行。 – Ironman

只要改变RelativeLayout财产

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

xmlns:app="http://schemas.android.com/apk/lib/com.example.jaisonjoseph.newsclient" 

编辑:

添加此

xmlns:app="http://schemas.android.com/apk/lib/com.example.jaisonjoseph.newsclient" 

欲了解更多详情,请登录本:No resource identifier found for attribute ' ' in package 'com.app....'

完整代码:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/lib/com.example.jaisonjoseph.newsclient" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:context="com.example.jaisonjoseph.newsclient.MainActivity" 
     tools:showIn="@layout/app_bar_main" 
     style="@style/Base.Widget.AppCompat.ButtonBar" 
     android:background="#ffffff"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/card_view" 
     android:layout_width="350dp" 
     android:layout_height="150dp" 
     app:cardCornerRadius="6dp" 
     android:background="#f6f6f6" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true"> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      app:srcCompat="@drawable/daily" 
      android:id="@+id/imageButton3" 
      android:src="@drawable/daily" /> 
    </android.support.v7.widget.CardView> 
</RelativeLayout> 
+0

+0

这是我的软件包名称,可以编辑并给我正确的值@lroman –

+0

@Jaison_Joseph查看我的编辑 – Ironman

什么你得到它好像它只是一个可以被忽略的皮棉错误或。

你可以使用:

tools:ignore="MissingPrefix"

RelativeLayout避免暂时看到此错误。

因为srcCompat属性中程序兼容性库实际上定义,所以记得要程序兼容性库添加到您的项目。


UPDATE
对于其他读者如何降落在这个线程。

不要使用的应用程序的命名空间中的项目名称,如:

xmlns:app="http://schemas.android.com/apk/res/com.yourproject.name"

而是使用:

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

正如在https://code.google.com/p/android/issues/detail?id=9656#c71说:

"Added support for custom views with custom attributes in libraries. Layouts using custom attributes must use the namespace URI schemas.android.com/apk/res-autoinstead of the URI that includes the app package name. This URI is replaced with the app specific one at build time."

更多详情https://code.google.com/p/android/issues/detail?id=9656

+0

我可以idd AppCompat库 –

+1

添加到您的应用程序build.gradle'dependencies'下面的代码: com.android.support:appcompat-v7:24.2.1 –