From what I understand, early in the preview stage there seemed to be no way to set elevation in XML only on CardView
s without a hack in Java. Now that the official release is out, is there any way of doing this in XML without writing Java code to set elevation?
I have tried card_view:cardElevation
to no effect. I had thought when I was using the emulators for 5.0 everything was fine. But now that I'm using the official version on my actual device all of my CardView
s disappeared
Pre Lollipop, it works great.
Here is my full xml
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="horizontal"
android:layout_width="match_parent"
android:id="@+id/cv1"
card_view:cardElevation="4dp"
android:layout_margin="6dp"
card_view:cardCornerRadius="3dp"
android:layout_height="match_parent">
It solved me by adding
xmlns:card_view="http://schemas.android.com/apk/res-auto"
for example:
If you have this line
in manifest application tag your shadows were not displayed. try to remove this line
or use
This worked for me! I hope it works for you too :)
You have to use the cardElevation attribute
It looks like a margin/padding problem, try to set the cardUseCompatPadding attribute to true. E.g.:
Explanation from Android doc :