The new floating action button should be 56dp x 56dp and the icon inside it should be 24dp x 24dp. So the space between icon and button should be 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>
And this is the result I get:
I used the icon from \material-design-icons-1.0.0\content\drawable-hdpi\ic_add_black_48dp.png
https://github.com/google/material-design-icons/releases/tag/1.0.1
How to make the size of the icon inside the button be exactly as described in guidelines ?
http://www.google.com/design/spec/components/buttons.html#buttons-floating-action-button
What's your goal?
If set icon image size to bigger one:
Make sure to have a bigger image size than your target size
(so you can set max image size for your icon)
My target icon image size is 84dp & fab size is 112dp:
If you are using androidx 1.0.0 and are using a custom fab size, you will have to specify the custom size using
By deafult the size is 56dp and there is another variation that is the small sized fab which is 40dp, if you are using anything you will have to specify it for the padding to be calculated correctly
Make this entry in dimens
Here 36dp is icon size on floating point button. This will set 36dp size for all icons for floating action button.
Updates As Per Comments
If you want to set icon size to particular Floating Action Button then you have to go with Floating action button attributes like app:fabSize="normal" and android:scaleType="center".
The design guidelines defines two sizes and unless there is a strong reason to deviate from using either, the size can be controlled with the
fabSize
XML attribute of theFloatingActionButton
component.Consider specifying using either
app:fabSize="normal"
orapp:fabSize="mini"
, e.g.:As your content is 24dp x 24dp you should use 24dp icon. And then set
android:scaleType="center"
in your ImageButton to avoid auto resize.off of @IRadha's answer in vector drawable setting
android:height="_dp"
and setting the scale type toandroid:scaleType="center"
sets the drawable to whatever size was set