I have a CardView and I wanted to shape the corners of the cardview, I found a xml code snippet here and added it to my cardview and get this error, please look at the comment in the test.xml
layout
EDIT: When I change background of the cardview to "#ffffff" (white) it works. It only crashes when I use card_view:cardBackgroundColor="@drawable/ic_corner_color"
EDIT 2: I want the corners look like this in the picture in the question, click
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.app/com.example.user.app.Test}: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.widget.CardView
This is my test.xml
layout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:tag="cards main container">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_viewtest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@drawable/ic_corner_color" **// here is the error**
card_view:cardCornerRadius="10dp"
card_view:cardElevation="5dp"
card_view:cardUseCompatPadding="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_weight="2"
android:orientation="vertical"
android:weightSum="1">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.96"
android:background="#ffffff"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme">
<ImageView
android:id="@+id/imageViewtest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="@drawable/ic_drive_eta_black_24dp"
android:tag="image_tag" />
</android.support.v7.widget.Toolbar>
<TextView
android:id="@+id/textViewNametest"
android:layout_width="340dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_weight="0.96"
android:text="some
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
My ic_corner_color.xml
, which is in the drawable folder, looks like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#00ff00"/>
<corners android:radius="20dip"/>