How to remove auto padding of FAB button in android?

人走茶凉 提交于 2019-12-03 09:43:03

问题


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.


回答1:


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.




回答2:


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.




回答3:


add this in your fab xml layout

android:elevation="0dp"
app:elevation="10dp"
app:useCompatPadding="true"

This will do the job. Worked perfectly for me.



来源:https://stackoverflow.com/questions/38567663/how-to-remove-auto-padding-of-fab-button-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!