Warm tip: This article is reproduced from stackoverflow.com, please click
android android-support-library floating-action-button androiddesignsupport

Is it possible to change FloatingActionButton size at runtime programatically?

发布于 2020-03-27 10:30:47

I am using FloatingActionButton from support library. I noticed that size can only be changed in the XML using the attribute app:fab_size="".

I looked at the source code and there are no methods that would allow to change the fab size when app is running.

I simply want to change fab's size between MINI and NORMAL based on the user input, so I need to do it programatically.

Has anyone find a way to do this yet?

Questioner
Guy
Viewed
22
x0r 2016-05-19 19:07

It is not possible. Size is determined upon FloatingActionButton creation and remains static during its lifecycle. There are no public methods that allow to change the size dynamically. Of course you could use java reflection in order to access private size and padding fields and change them, but that's not a good idea. Alternatively, you can take a look at some 3rd party implementation, which allows changing button's size dynamically, this one for example