Add CardView to Android OS versions below L ()

You might notice the new CardView widget on Android L preview presentation. The view can be used to display text or images and has a nice shadow.

You can add that view into your project even if you don’t have the minimum API level to “L”… to do that, follow the steps below:

1.  Edit your gradle.build file to:

dependencies {
    // your other dependencies
    compile 'com.android.support:cardview-v7:21.+' // this will load the CardView
}

2. Edit your manifest file and add the following tag

<uses-sdk tools:node="replace" />

Make sure you import the XML schema first in the main tag:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 package="com.yourpackage" >

You might remember that from a previous post.
That will help you fix the Manifest.xml merging issue and avoid the following error:

Error:Execution failed for task ':TestApp:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version L declared in library com.android.support:cardview-v7:21.0.0-rc1

3. Use the CardView from the package: android.support.v7.widget like this:

<android.support.v7.widget.CardView
 android:id="@+id/some_card_view"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_alignParentLeft="true">
<LinearLayout
 android:id="@+id/some_view"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>

That should be all 🙂

 

 

keyboard_arrow_up