Reputation: 856
I am trying to use a cardview in my project, but while I am creating my XML file for my cardview, I keep getting the error
error: Error parsing XML: unbound prefix
but if I take out my cardview widget, it works. I looked at other questions and tried their responses but it isn't working. Does anyone see what is wrong with my code?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
card_view:cardCornerRadius="2dp" >
</android.support.v7.widget.CardView>
</LinearLayout>
Upvotes: 0
Views: 3652
Reputation: 133560
Try this
<LinearLayout
xmlns:card_view="http://schemas.android.com/apk/res-auto"
You are missing the prefix for card_view
.
This is necessary when using any XML attributes defined by the support library, because these attributes do not exist in the Android framework on older devices.
You could also do
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
Upvotes: 2
Reputation: 499
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="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:orientation="horizontal" >
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
card_view:cardCornerRadius="2dp" >
</android.support.v7.widget.CardView>
you should add xmlns:card_view="http://schemas.android.com/apk/res-auto"
this for your parent layout
Upvotes: 2