错误:(27)未找到属性“srcCompat”中包“com.example.jaisonjoseph.newsclient”资源标识符
我添加了一个
ImageButton
我CardView
,当我加入app:srcComapat
我ImageButton
。我发现了一个错误,如下面:错误:(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>
只要改变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>
什么你得到它好像它只是一个可以被忽略的皮棉错误或。
你可以使用:
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."
我可以idd AppCompat库 –
添加到您的应用程序build.gradle'dependencies'下面的代码: com.android.support:appcompat-v7:24.2.1 –
删除'RelativeLayout'中的'xmlns:app2'行。 – Ironman