Elevation on Android Lollipop not working
For some reason if you set a solid color with a transparency, the elevation shadow does not show up.
In your example, I changed #7d0073ff to #0073ff and I got a shadow.
This is probably a bug, as in their documentation it gives a similar example using a translucent background color.
Elevation on Android 5.0 (Lollipop) not working
It looks like bug in Docs. Background with alpha doesn't drop shadow. Make the background color without alpha, and it will work.
Related question: Elevation on Android Lollipop not working
android:elevation= doesn't work on devices pre-Lollipop with compile API21
Elevation requires the device to run Lollipop. See this answer on how to simulate elevation https://stackoverflow.com/a/26747592/680249
CardView elevation not showing in lollipop and higher versions
this worked for me.
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
total code is:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_margin="8dp"
android:id="@+id/card_griditem"
android:layout_height="match_parent"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="4dp"
card_view:cardCornerRadius="3dp">`
Android elevation not showing a shadow
I've been playing around with shadows on Lollipop for a bit and this is what I've found:
- It appears that a parent
ViewGroup
's bounds cutoff the shadow of its children for some reason; and - shadows set with
android:elevation
are cutoff by theView
's bounds, not the bounds extended through the margin; - the right way to get a child view to show shadow is to set padding on the parent and set
android:clipToPadding="false"
on that parent.
Here's my suggestion to you based on what I know:
- Set your top-level
RelativeLayout
to have padding equal to the margins you've set on the relative layout that you want to show shadow; - set
android:clipToPadding="false"
on the sameRelativeLayout
; - Remove the margin from the
RelativeLayout
that also has elevation set; - [EDIT] you may also need to set a non-transparent background color on the child layout that needs elevation.
At the end of the day, your top-level relative layout should look like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/block"
android:gravity="center"
android:layout_gravity="center"
android:background="@color/lightgray"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:clipToPadding="false"
>
The interior relative layout should look like this:
<RelativeLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:background="[some non-transparent color]"
android:elevation="30dp"
>
Elevation on SlidingTabLayout in pre lollipop device
I found solutions through here, replace "android=elevation=" with a drawable xml file.
Related Topics
Is Deprecated Word the Only Difference Between Fill_Parent and Match_Parent
Why Is My Field 'Null' After Injection? How to Inject My Object
Which Port and Protocol Does Google Cloud Messaging (Gcm) Use
Android Detect Usb Storage for Kitkat (4.4)
How to Launch an Activity Without a Ui
Android Task Affinity Explanation
Advantages of Using Bundle Instead of Direct Intent Putextra() in Android
Adding Custom Font to Theme in Android
Fragment Inner Class Should Be Static
Android - Build Separate APKs for Different Processor Architectures
Notifydatasetchanged Not Working on Recyclerview
Android Spinner Error:Android.View.Windowmanager$Badtokenexception: Unable to Add Window
Android - Firebase Quickstart Email/Password Auth Demo Doesn't Work
Resize Image to Full Width and Variable Height with Picasso
How to Display Both Icon and Title of Action Inside Actionbar