Hiromi
Hiromi

Reputation: 229

CardView how to change shadow color and angle?

How to change shadow color and angle in CardView ? I've put cardview_shadow_start_color and cardview_shadow_end_color into colors.xml but no colors changes... Txs !

Upvotes: 8

Views: 15541

Answers (3)

Marina
Marina

Reputation: 417

In API level 28 and higher now we can use:

android:outlineAmbientShadowColor="@color/blue_buttons"
android:outlineSpotShadowColor="@color/blue_buttons"

Upvotes: 0

dud3rino
dud3rino

Reputation: 527

I don't think there's a way to change the angle and color of the shadow, but you can try with CardView's elevation (the shadow will get more dispersed, but longer).

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
    ... 
    card_view:cardElevation="8dp">
</android.support.v7.widget.CardView>

Upvotes: -2

Zielony
Zielony

Reputation: 16537

There's no way to change shadow color and angle in the official Android framework. The color is always black and the angle is generated automatically using view's position. Moreover, on older platforms CardView's shadow is a completly different thing than on Lollipop, so the angle won't work at all.

For colored shadows you can use a library called Carbon. See this answer: Android change Material elevation shadow color

Upvotes: 3

Related Questions