标题很不言自明。
下面的代码不呈现浮动Action Button下面的阴影。可以做些什么来渲染阴影?在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
发布于 2015-06-10 17:44:24
对于21+接口,需要设置app:borderWidth="0dp"
和app:elevation="[number]dp"
。设置高程您正在提供所需的阴影大小:
以下是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 (Android 4)的API,有一件重要的事情要记住,就是兼容性方面,FAB会在你的按钮周围加一个边距来绘制阴影。那么你应该这样做(我目前正在使用这段代码,并且工作正常):
<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">
我更喜欢将xmlns:app="http://schemas.android.com/apk/res-auto"
放在XML的开头,但我把它放在那里只是为了提醒您;]
发布于 2017-03-13 19:47:35
我也遇到了同样的问题,我从我的AndroidManifest.xml中删除了这个标签,让它正常工作。
android:hardwareAccelerated="false"
我最初将它与android:largeHeap="true"
一起添加,因为我认为我需要在HeatMap中显示大量的点,但后来我意识到它可以只与android:largeHeap="true"
一起工作。
发布于 2016-05-11 07:54:15
如果这对某些人来说仍然不起作用,那么在以下两种情况之间存在显著的差异:
app:elevation="6dp"
app:borderWidth="0dp"
和
app:borderWidth="0dp"
app:elevation="6dp"
由于某些原因,顺序似乎很重要(第一个顺序有效,第二个顺序不起作用),这来自支持库23.3.0
https://stackoverflow.com/questions/30532863
复制相似问题