Elevation on Android Lollipop Not Working

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:

  1. It appears that a parent ViewGroup's bounds cutoff the shadow of its children for some reason; and
  2. shadows set with android:elevation are cutoff by the View's bounds, not the bounds extended through the margin;
  3. 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:

  1. 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;
  2. set android:clipToPadding="false" on the same RelativeLayout;
  3. Remove the margin from the RelativeLayout that also has elevation set;
  4. [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



Leave a reply



Submit