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


当前回答

<ImageButton
        android:background="@drawable/action_button_bg"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:padding="16dp"
        android:src="@drawable/ic_add_black_48dp"
        android:scaleType="fitXY"
        android:elevation="8dp"/>

在你提供的背景下,它会在我的设备上出现以下按钮(Nexus 7 2012)

我觉得不错。

其他回答

因为你的内容是24dp x 24dp,你应该使用24dp图标。然后在ImageButton中设置android:scaleType="center"以避免自动调整大小。

您可以轻松设置您的FAB图标大小使用,

final FloatingActionButton按钮= new FloatingActionButton(context); button.setCustomSize (50);

你的目标是什么?

如果将图标图像大小设置为较大:

确保图像大小大于你的目标大小(这样你就可以为你的图标设置最大图像大小) 我的目标图标图像大小是84dp, fab大小是112dp: < android.support.design.widget.FloatingActionButton android: layout_width = " wrap_content " android: layout_height = " wrap_content " android: layout_gravity = "中心" Android:src= <image here> 应用:fabCustomSize = " 112 dp” 应用:fabSize =“自动” 应用:maxImageSize = " 84 dp " / >

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

app:iconSize="<x>dp"

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

使这一项以维数表示

<!--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"