如何添加阴影到Android支持devise库提供的FAB?

标题是很自我解释。

以下代码不会在浮动操作button下方呈现阴影。 可以做什么来渲染阴影? 这个function是否真的不支持API 21+?

<android.support.design.widget.FloatingActionButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/ic_add" android:clickable="true" /> 

注意:添加android:elevation不会在API 21上添加阴影。

示例截图

从dandar3的示例中截取的截图: https : //github.com/dandar3/android-support-design

只需设置app:borderWidth="0dp"为我解决这个问题。

注意:不要忘记将xmlns:app="http://schemas.android.com/apk/res-auto"到您的根布局。

这个问题应该在androiddevise库的下一个版本中解决。

对于API 21+,您需要设置app:borderWidth="0dp"app:elevation="[number]dp" 。 设置提升你正在给你的阴影大小,你想要的:

参数“高程”的值的示例

以下是API 21+的代码示例:

 <android.support.design.widget.FloatingActionButton xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/locate_user_FAB" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/location_off" app:elevation="6dp" app:borderWidth="0dp" android:layout_above="@+id/take_taxi_FAB" app:backgroundTint="@color/colorAccentGrey"> 

对于21以下的API(Android 4),要记住的一件重要事情是兼容性方面,FAB会在button周围留出一些空白来画出阴影。 那么你应该做这样的事情(我目前正在使用这个代码和工作):

 <android.support.design.widget.FloatingActionButton xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/locate_user_FAB" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/location_off" app:elevation="6dp" app:borderWidth="0dp" android:layout_above="@+id/take_taxi_FAB" android:layout_alignParentRight="true" android:layout_marginRight="@dimen/map_FAB_marginRight" android:layout_marginBottom="@dimen/locate_user_FAB_marginBottom" app:backgroundTint="@color/colorAccentGrey"> 

我更喜欢在XML的开头放置xmlns:app="http://schemas.android.com/apk/res-auto" ,但是我只是想提醒你;]

如果这还没有为一些工作,有一个重大的区别:

 app:elevation="6dp" app:borderWidth="0dp" 

 app:borderWidth="0dp" app:elevation="6dp" 

顺序似乎是由于某种原因(第一顺序工作,第二不),这是从支持库23.3.0

我遇到了同样的问题,我从AndroidManifest.xml中删除了这个标签。

 android:hardwareAccelerated="false" 

我最初添加它与android:largeHeap="true" ,因为我认为我需要一个HeatMap,其中显示了大量的点,但后来我意识到它只能用于android:largeHeap="true"

检查应用程序标签中的项目或库中的清单,并将其删除

 android:hardwareAccelerated="false" android:largeHeap="true" 

但是如果你需要这些选项,阴影和转换animation将不起作用