Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting behaviour of Floating Action Button programmatically

I'm using the following guide to implement a scroll aware FAB:

https://guides.codepath.com/android/Floating-Action-Buttons#overview

After creating the class, you set up the behaviour by declaring it in XML as follows:

<android.support.design.widget.FloatingActionButton    
app:layout_behavior="com.codepath.floatingactionbuttontest.ScrollAwareFABBehavior" />

Due to how my code is written, I want to set the behaviour programmatically and not in the XML. I have a feeling that this is done with the CoordinatorLayout but I'm drawing a blank.

Any help would be appreciated!

Thanks in advance.

like image 469
Adam Avatar asked Aug 12 '15 18:08

Adam


People also ask

How do you adjust a floating button?

Add the floating action button to your layoutThe 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.

How do you make a floating action rectangular button?

How do you make a floating action button on a rectangle flutter? To change the shape of the Floating action button: You can use the shape property of FloatingActionButton() widget class. Implement BeveledRectangleBorder( ) on this property.


1 Answers

You can use somenthing like this:

CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setBehavior(xxxx);
fab.setLayoutParams(p);
like image 91
Gabriele Mariotti Avatar answered Nov 03 '22 22:11

Gabriele Mariotti