新的浮动动作按钮应该是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


当前回答

因为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。

其他回答

在你更新你的支持库到v28.0.0后,尝试使用app:maxImageSize="56dp"来代替上面的答案

因为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。

你可以使用FloatingActionButton的以下设置:android:scaleType和app:maxImageSize。对于我来说,我得到了一个理想的结果,如果android:scaleType=“centerInside”和app:maxImageSize=“56dp”。

使用ExtendedFloatingActionButton,这解决了我的问题:

app:iconSize="<x>dp"

我尝试过iconPadding或fabCustomSize,但我似乎没有任何变化

设计指南定义了两种大小,除非有强烈的理由不使用其中任何一种,否则大小可以通过FloatingActionButton组件的fabSize XML属性来控制。

考虑使用app:fabSize="normal"或app:fabSize="mini"来指定,例如:

<android.support.design.widget.FloatingActionButton
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/ic_done_white_24px"
   app:fabSize="mini" />