So I have started migrating to the official support design library for an Android app of mine, replacing elements as I go. I just replaced an FAB
(implemented as ImageButton
) with official android.support.design.widget.FloatingActionButton
. But the icon inside the button is smaller as compared to the one it was in ImageButton
. What may have been a reason?
FloatingActionButton
's implementation:
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon" />
Tried adding app:fabSize="normal
but that didn't work, either.
This is how it looks after using FloatingActionButton
:
And this is how it looked like while using it as a ImageButton
:
By default, the floating action button in flutter is 56 logical pixels height and width. This is the normal size or non-mini size. If you add this property mini with a value true, it will create a smaller floating action button.
The solution is app:maxImageSize = "56dp" property set to your FAB. Have an image or vector asset, preferably in perfect circle shape and perfectly fit to canvass (no empty margins). Know the actual size of Floating Action Bar (FAB) - Default (56 x 56dp) or Mini (40 x 40dp). Save this answer.
Floating Action Button using Fab Option Library in Android.
Set scale type to android:scaleType="center"
Just a guess since you haven't provided any details at all. The design library's FloatingActionButton
has padding calculations which will shrink the icon if it is too large, whereas your ImageButton
probably just centers the icon with no scaling at all. I'm guessing that you would not observe this behavior if you were using a correctly sized 24dp icon, like the ones you get from: https://www.google.com/design/icons/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With