Changing floating button image size programmatically

て烟熏妆下的殇ゞ 提交于 2019-12-02 10:31:23

When you set the maxImageSize in the XML, you are changing the normal behavior and icon size of the FAB.

<com.google.android.material.floatingactionbutton.FloatingActionButton
            android:adjustViewBounds="true"
            android:id="@+id/fab_main"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/ic_home"
            app:backgroundTint="@color/colorBottomAppBarFab"
            app:fabSize="normal"
            app:layout_anchor="@+id/bottom_app_bar"
            app:maxImageSize="56dp"/>

The result of this code is : FAB with image size 56dp

Later to change it again but programatically, you can use ScaleType to change the icon dimensions. Here an example in Kotlin:

fab_main.scaleType = ImageView.ScaleType.CENTER_INSIDE

And then, here is the new result: FAB with smaller icon size

If you want to change FAB dimensions, may be using one of the following methods can help you: FAB methods

I hope this solution can help you.

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