Skip to content

Most visited

Recently visited

navigation

FloatingActionButton.Behavior

public static class FloatingActionButton.Behavior
extends Behavior<FloatingActionButton>

java.lang.Object
   ↳ android.support.design.widget.CoordinatorLayout.Behavior<android.support.design.widget.FloatingActionButton>
     ↳ android.support.design.widget.FloatingActionButton.Behavior


Behavior designed for use with FloatingActionButton instances. Its main function is to move FloatingActionButton views so that any displayed Snackbars do not cover them.

Summary

XML attributes

android.support.design:behavior_autoHide Whether the FAB should automatically hide when there is no space for it. 

Public constructors

FloatingActionButton.Behavior()
FloatingActionButton.Behavior(Context context, AttributeSet attrs)

Public methods

boolean getInsetDodgeRect(CoordinatorLayout parent, FloatingActionButton child, Rect rect)

Called when a view is set to dodge view insets.

boolean isAutoHideEnabled()

Returns whether the associated FloatingActionButton automatically hides when there is not enough space to be displayed.

void onAttachedToLayoutParams(CoordinatorLayout.LayoutParams lp)

Called when the Behavior has been attached to a LayoutParams instance.

boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton child, View dependency)

Respond to a change in a child's dependent view

This method is called whenever a dependent view changes in size or position outside of the standard layout flow.

boolean onLayoutChild(CoordinatorLayout parent, FloatingActionButton child, int layoutDirection)

Called when the parent CoordinatorLayout is about the lay out the given child view.

void setAutoHideEnabled(boolean autoHide)

Sets whether the associated FloatingActionButton automatically hides when there is not enough space to be displayed.

Inherited methods

From class android.support.design.widget.CoordinatorLayout.Behavior
From class java.lang.Object

XML attributes

android.support.design:behavior_autoHide

Whether the FAB should automatically hide when there is no space for it.

May be a boolean value, such as "true" or "false".

Related methods:

Public constructors

FloatingActionButton.Behavior

added in version 22.2.0
FloatingActionButton.Behavior ()

FloatingActionButton.Behavior

added in version 24.0.0
FloatingActionButton.Behavior (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

Public methods

getInsetDodgeRect

added in version 24.2.0
boolean getInsetDodgeRect (CoordinatorLayout parent, 
                FloatingActionButton child, 
                Rect rect)

Called when a view is set to dodge view insets.

This method allows a behavior to update the rectangle that should be dodged. The rectangle should be in the parent's coordinate system and within the child's bounds. If not, a IllegalArgumentException is thrown.

Parameters
parent CoordinatorLayout: the CoordinatorLayout parent of the view this Behavior is associated with

child FloatingActionButton: the child view of the CoordinatorLayout this Behavior is associated with

rect Rect: the rect to update with the dodge rectangle

Returns
boolean true the rect was updated, false if we should use the child's bounds

isAutoHideEnabled

added in version 24.2.0
boolean isAutoHideEnabled ()

Returns whether the associated FloatingActionButton automatically hides when there is not enough space to be displayed.

Related XML Attributes:

Returns
boolean true if enabled

onAttachedToLayoutParams

added in version 24.2.0
void onAttachedToLayoutParams (CoordinatorLayout.LayoutParams lp)

Called when the Behavior has been attached to a LayoutParams instance.

This will be called after the LayoutParams has been instantiated and can be modified.

Parameters
lp CoordinatorLayout.LayoutParams: the LayoutParams instance that this Behavior has been attached to

onDependentViewChanged

added in version 22.2.0
boolean onDependentViewChanged (CoordinatorLayout parent, 
                FloatingActionButton child, 
                View dependency)

Respond to a change in a child's dependent view

This method is called whenever a dependent view changes in size or position outside of the standard layout flow. A Behavior may use this method to appropriately update the child view in response.

A view's dependency is determined by layoutDependsOn(CoordinatorLayout, android.view.View, android.view.View) or if child has set another view as it's anchor.

Note that if a Behavior changes the layout of a child via this method, it should also be able to reconstruct the correct position in onLayoutChild. onDependentViewChanged will not be called during normal layout since the layout of each child view will always happen in dependency order.

If the Behavior changes the child view's size or position, it should return true. The default implementation returns false.

Parameters
parent CoordinatorLayout: the parent view of the given child

child FloatingActionButton: the child view to manipulate

dependency View: the dependent view that changed

Returns
boolean true if the Behavior changed the child view's size or position, false otherwise

onLayoutChild

added in version 22.2.1
boolean onLayoutChild (CoordinatorLayout parent, 
                FloatingActionButton child, 
                int layoutDirection)

Called when the parent CoordinatorLayout is about the lay out the given child view.

This method can be used to perform custom or modified layout of a child view in place of the default child layout behavior. The Behavior's implementation can delegate to the standard CoordinatorLayout measurement behavior by calling parent.onLayoutChild.

If a Behavior implements onDependentViewChanged(CoordinatorLayout, android.view.View, android.view.View) to change the position of a view in response to a dependent view changing, it should also implement onLayoutChild in such a way that respects those dependent views. onLayoutChild will always be called for a dependent view after its dependency has been laid out.

Parameters
parent CoordinatorLayout: the parent CoordinatorLayout

child FloatingActionButton: child view to lay out

layoutDirection int: the resolved layout direction for the CoordinatorLayout, such as LAYOUT_DIRECTION_LTR or LAYOUT_DIRECTION_RTL.

Returns
boolean true if the Behavior performed layout of the child view, false to request default layout behavior

setAutoHideEnabled

added in version 24.2.0
void setAutoHideEnabled (boolean autoHide)

Sets whether the associated FloatingActionButton automatically hides when there is not enough space to be displayed. This works with AppBarLayout and BottomSheetBehavior.

Related XML Attributes:

Parameters
autoHide boolean: true to enable automatic hiding

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)