海拔在Android棒棒糖不工作棒棒糖、海拔、工作、Android

2023-09-12 06:28:00 作者:娜样杰出的星光

我试图在最新的Andr​​oid棒棒堂preVIEW发布使用高程属性。我设置了targetSdk为21和主题材料。接下来我添加了一个背景形状,一个TextView,设置海拔8DP但TextView中没有显示阴影的迹象。这是一个Nexus7运行棒棒堂preVIEW。还有什么我要考虑?

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?

下面的布局:

<?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>

这是背景绘制:

<?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>

下面是TextView的:

Here is the TextView:

推荐答案

出于某种原因,如果你设置了坚实的颜色与透明度,海拔阴影并没有显示出来。

For some reason if you set a solid color with a transparency, the elevation shadow does not show up.

在你的榜样,我改变#7d0073ff为#0073ff,我得到了一个阴影。

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.