Reputation: 2399
How to implement shadows like the image below?
I try many ways as CardView
, elevation
, many custom views
, drawable
. But that was different from the wanted shadows.
elevation of CardView
is ambient light
+ key light
. But, I want just ambient light
elevation.
Upvotes: 7
Views: 4355
Reputation: 350
Starting with API 28 you can set the color of the shadows.
If you want the ambient shadow only, then you need to set the color of the key light(aka spot light) to transparent.
You can do so by adding the following to your view tag in xml:
android:outlineAmbientShadowColor="@android:color/transparent"
Now only key/spot light will show.
and for ambient shadow
android:outlinesSpotShadowColor="@android:color/transparent"
Also check
setOutlineAmbientShadowColor() and setOutlinePostShadowColor()
to do it programmatically
You can also set them to other colors if you don't want a black shadow.
Upvotes: 3