Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elevation on Android Lollipop not working

I am trying to make use of the elevation property in the latest Android Lollipop preview release. I set the targetSdk to 21 and the theme to Material. Next i added a background shape to a TextView and set the elevation to 8dp but the TextView is not showing any signs of a shadow. That is on a Nexus7 running the Lollipop preview. Is there anything else i have to consider?

Here is the layout:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"           android:layout_width="match_parent"           android:layout_height="match_parent">    <TextView       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:background="@drawable/rect"       android:text="hallo world"       android:padding="8dp"       android:elevation="8dp" />  </LinearLayout> 

This is the background drawable:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"      android:shape="rectangle">     <solid android:color="#7d0073ff" />     <corners android:radius="16dp" /> </shape> 

Here is the TextView:

Android elevation

like image 286
Moritz Avatar asked Oct 26 '14 10:10

Moritz


People also ask

How do I get elevation on my Android?

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.

What is elevation in XML?

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).

Why doesn't the elevation style property work on Android?

The elevation style property on Android does not work unless backgroundColor has been specified for the element. With backgroundColor applied to instructions element: Unless I'm missing something elevation should get applied regardless of whether a view has a background color or not. React Native version: 0.33 Platform (s) (iOS, Android, or both?):

What are the problems with Android 5 Lollipop?

That’s all the Android 5.0 Lollipop problems we have for now, but we’ll add more issues and potential solutions as we discover them. Updated on 2-9-2016 by Simon Hill: Added problems with flashlight, camera, closing apps, GPS, and mobile network.

Is it possible to use elevation style without background color?

Android - elevation style property does not work without backgroundColor. · Issue #10411 · facebook/react-native · GitHub Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Why is my camera not working after updating to Lollipop?

Quite a few people have been having trouble with the camera after updating to Lollipop. This could be linked to our previous bug with the flashlight, but there are other potential reasons for the camera to crash, or return an error message and refuse to load.


1 Answers

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.

like image 189
rlay3 Avatar answered Oct 05 '22 20:10

rlay3