I am using CardView inside a RecyclerView. After reading a lot I ended up with following \'NOT WORKING\' code only on Android 5.1.1. On Android Version prior to this one its
Just simply add this code to your Card View in xml file!
card_view:cardUseCompatPadding="true"
You have to import card_view with Alt+Enter ! And code below will be import in top !.
xmlns:card_view="http://schemas.android.com/apk/res-auto"
You'll see elevation is working on android 5 or 5+ .
remove this line from <application ...> </application>
in AndroidManifest.xml file
android:hardwareAccelerated="false"
change to
android:hardwareAccelerated="true"
for more details Hardware acceleration
Remove below line if you used in AndroidManifest.xml
android:hardwareAccelerated="false"
set in card view
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="6dp"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="4dp"
card_view:cardCornerRadius="3dp">
To make it both compatible above or below api 21, you need to specify app:cardUseCompatPadding="true" in your support CardView.
<android.support.v7.widget.CardView
app:cardElevation="4dp"
app:cardUseCompatPadding="true"
app:cardMaxElevation="6dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.CardView>