I am working with cardviews but the problem is my CardView is not showing any elevation or shadow. I have already tried some of the methods suggested in stackoverflow answer
<android.support.v7.widget.CardView android:id="@+id/item_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="2dp"
app:cardUseCompatPadding="true"
app:cardElevation="2dp"
app:cardBackgroundColor="@color/md_white_1000"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true">
</android.support.v7.widget.CardView>
app:cardUseCompatPadding="true"
is the main catch here
use this inside cardView to show shadow:
app:cardElevation="4dp"
app:cardMaxElevation="4dp"
Try this
<android.support.v7.widget.CardView
android:id="@+id/driverCurrentJobsCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dim_8"
android:background="#ffffff"
app:cardCornerRadius="4dp"
card_view:cardElevation="4dp"/>
And make sure that you are using this dependency in gradle
compile 'com.android.support:cardview-v7:23.2.1'
Lot of good answers, but sometimes just one doesn't work for all. here's the one that worked for me after a lot of looking around,
Add this line to your CardView
app:cardUseCompatPadding="true"
So your cardview looks like this
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
app:cardUseCompatPadding="true"/>
Hope that works! Happy coding!
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@android:color/white"
android:foreground="?android:attr/selectableItemBackground"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/padding_small"
android:layout_marginBottom="@dimen/padding_small"
app:cardCornerRadius="4dp"
app:cardElevation="4dp" >
</android.support.v7.widget.CardView>