Tuesday, July 21, 2015

How to create a drop shadow effect in android

          Recently on working on a project, My client requested me to add a shadow to an custom action bar layout.This was something i have never done before  so i decided to look for it. With my experience in CSS i was expecting a drop shadow to be enabled. But interestingly android doesnt have such a feature.
  But you can do a workaround. Here is how i do it.

1. Define a custom drawable  named it as shadow_drawable.xml ( inside res/drawable folder)

<shape xmlns:android="http://schemas.android.com/apk/res/android">

<gradient android:startColor="@color/background_material_dark"

And yes here is your shadow drawable. You could use it in your app always ( May be in another app too) if you can copy paste  :)

Lets look at how do we implement it.
I added it to a linear layout to have a drop shadow. So under the layout i added the following code.

<View     android:layout_below="@+id/some_layout_item"

  And thats it. Your drop shadow is now ready .  Adding a demo picture .

Happy coding  :)

No comments:

Post a Comment