The behavior of the Floating Action Button programmatically

I use the following guide to implement FAB with scrolling:

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

After creating the class, you configure the behavior by declaring it in XML as follows:

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

Due to the way my code is written, I want to set the behavior programmatically, not in XML. I have a feeling this is being done using CoordinatorLayout, but I'm drawing a space.

Any help would be appreciated!

Thanks in advance.

+4
source share
1 answer

You can use somenthing as follows:

 CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); p.setBehavior(xxxx); fab.setLayoutParams(p); 
+22
source

All Articles