Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove auto padding of FAB button in android?

I am using FAB button for profile picture but it is already having some padding. I am using following code for creating FAB button.

<android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="120dp" android:layout_height="120dp" android:layout_margin="@dimen/fab_margin" android:src="@drawable/student" app:layout_anchor="@id/app_bar" app:layout_anchorGravity="bottom|end"/>

How can i remove the padding which is automatically providing by library. I have also attached an screenshot of output. I want to remove this sky blue color and increase the size of src image.

enter image description here

like image 437
Shravan Jain Avatar asked Jul 25 '16 12:07

Shravan Jain


People also ask

How do you remove button padding?

You can remove the padding around the button by using setting the minWidth and minHeight to 0.

How do I get rid of shadow of Fab on Android?

To remove shadow of Floating Action Button in Kotlin Android, set the elevation attribute (in layout file) to 0dp or set compatElevation parameter (in Kotlin program) of FAB with floating point value of 0.0f.

How do you adjust the size of a floating action button?

Add the floating action button to your layout The size of the FAB, using the app:fabSize attribute or the setSize() method. The ripple color of the FAB, using the app:rippleColor attribute or the setRippleColor() method. The FAB icon, using the android:src attribute or the setImageDrawable() method.


2 Answers

just add this in your dimens.xml file

<dimen name="design_fab_image_size" tools:override="true">36dp</dimen>

This might not work for 3rd party libraries.

like image 129
Bawa Avatar answered Oct 09 '22 04:10

Bawa


You can changethe attribute app:maxImageSize to match the size of your image.

app:maxImageSize="the wanted size"

I find the solution safer the the overriding of the design_fab_image_size because if your app have several floating action buttons, you will only alter one.

like image 28
user2637476 Avatar answered Oct 09 '22 02:10

user2637476