Reputation: 751
I am using 'com.android.support:cardview-v7:23.4.0'
and I see the shadow but is not a dark grey shadow, and I would like to get a darker elevation shadow, but I do not see any attribute to get it, any ideas?
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="8dp"
app:cardElevation="8dp"
app:cardPreventCornerOverlap="false"
app:cardCornerRadius="1dp"
app:cardUseCompatPadding="false">
<include layout="@layout/any_layout"/>
</android.support.v7.widget.CardView>
Upvotes: 18
Views: 24406
Reputation: 81
<androidx.cardview.widget.CardView app:cardCornerRadius="10dp"
app:cardUseCompatPadding="true"
android:elevation="10dp"
android:outlineSpotShadowColor="@color/black"
android:outlineAmbientShadowColor="@color/grey"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
app:cardUseCompatPadding="true"
try this
Upvotes: 5
Reputation: 654
I believe that the shadow intensity is defined by the underlying theme that the app uses. So for API level more than 21, you can override the intensity of shadows. In your styles.xml
add these two extra lines of ambientShadowAlpha
and spotShadowAlpha
. Please note that these values range from 0 to 1, with 0 being completely transparent and 1 being completely opaque(almost black) :
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:fontFamily">@font/barlow_family</item>
<item name="android:ambientShadowAlpha">1</item>
<item name="android:spotShadowAlpha">1</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:statusBarColor">@android:color/background_light</item>
</style>
Upvotes: 47
Reputation: 781
You can't change cardView shadow color but to make it darker you can use app:cardElevation="15dp" like
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="10dp"
app:cardElevation="15dp"
> </android.support.v7.widget.CardView>
Upvotes: 1
Reputation: 1021
Try using this solution. Wrap your cardview in a RelativeLayout and give a background to it.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#FFE7E2E4">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardElevation="5dp"
app:cardUseCompatPadding="true"/>
</RelativeLayout>
Upvotes: 0
Reputation: 1041
there is no way to change color of official CardView elevation, look at this Carbon
Upvotes: 0