【发布时间】:2015-02-26 23:42:04
【问题描述】:
我正在尝试在棒棒糖之前的设备上制作一个浮动操作按钮。我设法制作了一个像样的按钮,但没有任何阴影它看起来并不好。
这里是 circle.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#ffffffff" />
<size android:width="40dp" android:height="40dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
还有图片按钮
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circle"
android:src="@drawable/ic_search"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:padding="10dp"
android:layout_margin="16dp"
/>
如何添加阴影让它看起来像 Material Design 浮动动作按钮?
【问题讨论】:
-
你可以使用自定义库...github.com/futuresimple/android-floating-action-button这些浮动按钮有阴影和许多其他有趣的属性
-
是的,已经看到了,但我只需要一个带阴影的按钮。
-
那会变得太复杂了。你将不得不用drawable做一些事情......就像这样stackoverflow.com/questions/15333529/…
-
你也可以在 xml 文件中为你的按钮尝试 android:elevation 属性....
-
海拔仅在 api 21 上可用
标签: android android-drawable material-design floating-action-button