The new floating action button should be 56dp x 56dp and the icon inside it should
off of @IRadha's answer
in vector drawable setting android:height="_dp"
and setting the scale type to android:scaleType="center"
sets the drawable to whatever size was set
Try to use app:maxImageSize="56dp"
instead of the above answers after you update your support library to v28.0.0
There are three key XML attributes for custom FABs:
app:fabSize
: Either "mini" (40dp), "normal"(56dp)(default) or "auto"app:fabCustomSize
: This will decide the overall FAB size.app:maxImageSize
: This will decide the icon size.Example:
app:fabCustomSize="64dp"
app:maxImageSize="32dp"
The FAB padding (the space between the icon and the background circle, aka ripple) is calculated implicitly by:
4-edge padding = (fabCustomSize - maxImageSize) / 2.0 = 16
Note that the margins of the fab can be set by the usual android:margin
xml tag properties.
You can play with the following settings of FloatingActionButton : android:scaleType and app:maxImageSize. As for me, I've got a desirable result if android:scaleType="centerInside" and app:maxImageSize="56dp".
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 the FloatingActionButton
component.
Consider specifying using either app:fabSize="normal"
or app:fabSize="mini"
, e.g.:
<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" />
<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"/>
With the background you provided it results in below button on my device (Nexus 7 2012)
Looks good to me.