Whiz Whiz - 1 year ago 100
Android Question

Is it possible to change FloatingActionButton size at runtime programatically?

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?

x0r x0r
Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download