新的浮动动作按钮应该是56dp x 56dp,图标应该是24dp x 24dp。所以图标和按钮之间的间距应该是16dp。
<ImageButton
android:id="@+id/fab_add"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:background="@drawable/ripple_oval"
android:elevation="8dp"
android:src="@drawable/ic_add_black_48dp" />
ripple_oval.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item>
<shape android:shape="oval">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
这是我得到的结果:
我使用了\material-design-icons-1.0.0\content\draw -hdpi\ic_add_black_48dp.png中的图标
https://github.com/google/material-design-icons/releases/tag/1.0.1
如何使按钮内的图标的大小完全按照指导方针所述?
http://www.google.com/design/spec/components/buttons.html#buttons-floating-action-button
使这一项以维数表示
<!--Floating action button-->
<dimen name="design_fab_image_size" tools:override="true">36dp</dimen>
这里36dp是浮点按钮上的图标大小。这将为浮动动作按钮的所有图标设置36dp大小。
根据评论更新
如果你想设置图标大小为特定的浮动动作按钮,只需使用浮动动作按钮属性,如app:fabSize="normal"和android:scaleType="center"。
<!--app:fabSize decides size of floating action button You can use normal, auto or mini as per need-->
app:fabSize="normal"
<!--android:scaleType decides how the icon drawable will be scaled on Floating action button. You can use center(to show scr image as original), fitXY, centerCrop, fitCenter, fitEnd, fitStart, centerInside.-->
android:scaleType="center"
因为FAB类似于ImageView,所以你可以使用scaleType属性来改变图标的大小。FAB的默认scaleType为fitCenter。你可以使用center和centerInside来使图标分别变小和变大。
scaleType属性的所有值是- center, centerCrop, centerInside, fitCenter, fitEnd, fitStart, fitXY和matrix。
详情见https://developer.android.com/reference/android/widget/ImageView.ScaleType.html。
定制fab有三个关键的XML属性:
app:fabSize:“mini”(40dp),“normal”(56dp)(默认)或“auto”
app:fabCustomSize:这将决定整个FAB的大小。
app:maxImageSize:这将决定图标大小。
例子:
app:fabCustomSize="64dp"
app:maxImageSize="32dp"
FAB填充(图标和背景圆之间的空间,又名波纹)隐式计算:
4-edge padding = (fabCustomSize - maxImageSize) / 2.0 = 16
注意,fab的页边距可以通过通常的android:margin xml标签属性设置。