salmanseifian
salmanseifian

Reputation: 1082

How to implement shadow in Android?

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

Upvotes: 2

Views: 548

Answers (2)

NIKHIL AGGARWAL
NIKHIL AGGARWAL

Reputation: 478

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.

Upvotes: 0

Mittal Patel
Mittal Patel

Reputation: 6089

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>

Upvotes: 1

Related Questions