In the Android 5.0 samples from the SDK Manager, there is the ElevationBasic
sample. It shows two View
objects: a circle and a square. The circle has android:elevation
set to 30dp
:
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/floating_shape"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginRight="40dp"
android:background="@drawable/shape"
android:elevation="30dp"
android:layout_gravity="center"/>
<View
android:id="@+id/floating_shape_2"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="25dp"
android:background="@drawable/shape2"
android:layout_gravity="center"/>
</FrameLayout>
On a Nexus 9, running the sample as-is, we get a drop shadow on the circle:
If we change the widget class to Button
, leaving all other attributes as-is, we lose the drop shadow on the circle:
The questions:
Why is the
android:elevation
behavior changing? It cannot be due to the background, because it is the same background in both cases.Which classes support
android:elevation
, and which do not? For example, usingTextView
instead ofView
orButton
still gives us the drop shadow, so this change in behavior is not introduced at theTextView
level, but rather at theButton
level.As seen in this question from yesterday, how do we get
android:elevation
to be honored on aButton
? Is there someandroid:allowElevationToWorkAsDocumented="true"
value that we have to put in a theme or something?
ElevationBasic
sample from the Android 5.0 samples, that you can download from the SDK Manager. I did not write the sample, though I amended it as noted in the question forButton
test. – Cooperstein