0

I've been searching for a couple of days how to make these color shadows and the elevation effect but it's not clear anywhere. What's the easiest way to do this?

enter image description here

enter image description here

  • I had the same problem. This saved me https://medium.com/@ArmanSo/take-control-of-views-shadow-android-c6b35ba573e9. Try to using Shape Drawable – Thorny84 Jan 18 '21 at 19:31

2 Answers2

1

Starting API 28 (Pie) View#setOutlineAmbientShadowColor(int color) and View#setOutlineSpotShadowColor(int color) are available in the View class.

If you use elevation on your View, you can use both methods to change the color of the shadow.

And you can use CardView to make shadows.

1

one of the simplest ways:

CardView

card view well as support elevation.

   <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:cardBackgroundColor="@android:color/white"
        app:cardElevation="20dp" />

Note: In the background of the card view only you can use simple color. if you want more options you can put your image or drawable in child background.

Like this:

   <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:cardElevation="20dp" >

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/flag_peru"  <= use this options
>
.
.


</androidx.constraintlayout.widget.ConstraintLayout>


</androidx.cardview.widget.CardView>
Pejman Azad
  • 165
  • 1
  • 11