I searched around, and I could not find a proper way to do this. I want to have the following shadow effects on my views:
To be honest, I do not know if this second one is done by applying shadow effect. Any ideas?
To set the default (resting) elevation of a view, use the android:elevation attribute in the XML layout. To set the elevation of a view in the code of an activity, use the View. setElevation() method. To set the translation of a view, use the View.
Kotlin Android – TextView Shadow Effect To get shadow for TextView in Android, set android:elevation attribute, with required amount of elevation from the base level, for the TextView widget in layout XML file. For elevation to be effective, we should set background for the TextView.
Elevation (Android) Elevation is the relative depth, or distance, between two surfaces along the z-axis. Specifications: Elevation is measured in the same units as the x and y axes, typically in density-independent pixels (dp).
I know this question has already been answered but I want you to know that I found a drawable
on Android Studio
that is very similar to the pics you have in the question:
Take a look at this:
android:background="@drawable/abc_menu_dropdown_panel_holo_light"
It looks like this:
Hope it will be helpful
Edit
The option above is for the older versions of Android Studio
so you may not find it. For newer versions:
android:background="@android:drawable/dialog_holo_light_frame"
Moreover, if you want to have your own custom shape, I suggest to use a drawing software like Photoshop
and draw it.
Don't forget to save it as .9.png
file (example: my_background.9.png
)
Read the documentation: Draw 9-patch
Edit 2
An even better and less hard working solution is to use a CardView
and set app:cardPreventCornerOverlap="false"
to prevent views to overlap the borders:
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="2dp"
app:cardElevation="2dp"
app:cardPreventCornerOverlap="false"
app:contentPadding="0dp">
<!-- your layout stuff here -->
</android.support.v7.widget.CardView>
Also make sure to have included the latest version in the build.gradle
, current is
compile 'com.android.support:cardview-v7:26.0.0'
I'm using Android Studio 0.8.6 and I couldn't find:
android:background="@drawable/abc_menu_dropdown_panel_holo_light"
so I found this instead:
android:background="@android:drawable/dialog_holo_light_frame"
and it looks like this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With