How to implement shadow in Android?-ThrowExceptions

Exception or error:

My UX designer has provided me with an elegant design and exported it as an Xd file. For shadows of some elements, Xd gives me below information:

Shadow color: #101F400D
X: 0dp
Y: 3dp 
Blur: 10dp

How can I create this layout in android with the above information?

Note: elevation is not what I want!

this is what i want to code

How to solve:

You can use cardView or Material design cardview to get the shadow effect

If you want to follow the guideline of material design you have to implement dependency

implementation 'com.google.android.material:material:1.2.0-alpha02'

You can use material cardview as shown below

 <com.google.android.material.card.MaterialCardView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:cardElevation="4dp"
                    app:cardBackgroundColor="@color/colorWhite">
</androidx.constraintlayout.widget.ConstraintLayout>

###

You have to use a nine patch image to achieve this. Create a nine patch image using any tool like this – https://inloop.github.io/shadow4android/

Then, set this image as background to your view.

Leave a Reply

Your email address will not be published. Required fields are marked *