This question was asked on SO many times, but still I didn't find a good solution for this problem.
Why do I need this to do? Well because project me and my team develops has iOS style.
What did I try?
So is there a way to change shadow color of CardView with minimum edits of all layout files and with drawing shadow outside of the view like original CardView does?
Use Fake Shadow. xml ) in the parent layout which is looking like a shadow. You can replace FF46A9 in shadow. xml to change the color of shadow. Also android:backgroundTint="@color/colorShadow" works but you have to adjust colors alpha in shadow.
Customized CardView First, add a CardView dependency to the application-level build. gradle file. Then create a drawable background for the cards. For that, create a new drawable resource file inside the drawable folder.
outlineSpotShadowColor.xmlSets the color of the spot shadow that is drawn when the view has a positive Z or elevation value. By default the shadow color is black.
CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other. The main usage of CardView is that it helps to give a rich feel and look to the UI design.
Consider this thread in twitter, where Nick Butcher talks about how to implement the feature:
See outlineAmbientShadowColor
, outlineSpotShadowColor
, spotShadowAlpha
and ambientShadowAlpha
attributes for details. Unfortunately, that's possible from API 28 onwards.
For lower APIs Nick has shared a gist. Here's the result:
Running on API 21
This technique isn't directly connected to CardView
, it can be applied to any View
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With