I'm trying to add a drop shadow to an ImageView. The other Stackoverflow answer seems to be using canvas and bitmaps etc, way more complicated than it needs to be. On iOS I would do something like...
original source : https://stackoverflow.com/questions/35170407/android-imageview-drop-shadow
In android studio there is in build drawable that you can use for apply shadow to any View. That is similar like a drop shadow.
android:background="@drawable/abc_menu_dropdown_panel_holo_light"
Using this you can not change the background color of the view & its border color. If you want your own custom drawable then use layer-list
custom_drop_shadow_drawable.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!--the shadow comes from here--> <item android:bottom="0dp" android:drawable="@android:drawable/dialog_holo_light_frame" android:left="0dp" android:right="0dp" android:top="0dp"> </item> <item android:bottom="0dp" android:left="0dp" android:right="0dp" android:top="0dp"> <!--whatever you want in the background, here i preferred solid white --> <shape android:shape="rectangle"> <solid android:color="@android:color/red" /> </shape> </item> </layer-list>
and apply to your view like below
android:background="@drawable/custom_drop_shadow_drawable"