Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

ExtendedFloatingActionButton

public class ExtendedFloatingActionButton
extends MaterialButton implements CoordinatorLayout.AttachedBehavior

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.Button
         ↳ androidx.appcompat.widget.AppCompatButton
           ↳ com.google.android.material.button.MaterialButton
             ↳ com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton


Extended floating action buttons are used for a special type of promoted action. They are distinguished by an icon and a text floating above the UI and have special motion behaviors related to morphing, launching, and the transferring anchor point.

Extended floating action buttons may have icon and text, but may also hold just an icon or text.

As this class descends from MaterialButton, you can control the icon which is displayed via setIcon(android.graphics.drawable.Drawable), and the text via setText(CharSequence).

The background color of this view defaults to the your theme's colorPrimary. If you wish to change this at runtime then you can do so via setBackgroundTintList(android.content.res.ColorStateList).

Summary

Nested classes

class ExtendedFloatingActionButton.ExtendedFloatingActionButtonBehavior<T extends ExtendedFloatingActionButton>

Behavior designed for use with ExtendedFloatingActionButton instances. 

class ExtendedFloatingActionButton.OnChangedCallback

Callback to be invoked when the visibility or the state of an ExtendedFloatingActionButton changes. 

XML attributes

ExtendedFloatingActionButton_extendMotionSpec  
ExtendedFloatingActionButton_hideMotionSpec  
ExtendedFloatingActionButton_showMotionSpec  
ExtendedFloatingActionButton_shrinkMotionSpec  

Inherited XML attributes

From class com.google.android.material.button.MaterialButton

Inherited constants

From class com.google.android.material.button.MaterialButton
From class android.widget.TextView
From class android.view.View

Inherited fields

From class android.view.View
From interface androidx.core.widget.AutoSizeableTextView

Public constructors

ExtendedFloatingActionButton(Context context)
ExtendedFloatingActionButton(Context context, AttributeSet attrs)
ExtendedFloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

void addOnExtendAnimationListener(Animator.AnimatorListener listener)

Add a listener that will be invoked when this ExtendedFloatingActionButton is extended.

void addOnHideAnimationListener(Animator.AnimatorListener listener)

Add a listener that will be invoked when this ExtendedFloatingActionButton is hidden.

void addOnShowAnimationListener(Animator.AnimatorListener listener)

Add a listener that will be invoked when this ExtendedFloatingActionButton is shown.

void addOnShrinkAnimationListener(Animator.AnimatorListener listener)

Add a listener that will be invoked when this ExtendedFloatingActionButton is shrunk.

void extend()

Extends the FAB to show the text and the icon.

void extend(ExtendedFloatingActionButton.OnChangedCallback callback)

Extends the FAB to show the text and the icon.

Behavior<ExtendedFloatingActionButton> getBehavior()
MotionSpec getExtendMotionSpec()

Returns the motion spec for the extend animation.

MotionSpec getHideMotionSpec()

Returns the motion spec for the hide animation.

MotionSpec getShowMotionSpec()

Returns the motion spec for the show animation.

MotionSpec getShrinkMotionSpec()

Returns the motion spec for the shrink animation.

void hide(ExtendedFloatingActionButton.OnChangedCallback callback)

Hides the button.

void hide()

Hides the button.

final boolean isExtended()
void removeOnExtendAnimationListener(Animator.AnimatorListener listener)

Remove a listener that was previously added via addOnExtendAnimationListener(AnimatorListener).

void removeOnHideAnimationListener(Animator.AnimatorListener listener)

Remove a listener that was previously added via addOnHideAnimationListener(AnimatorListener).

void removeOnShowAnimationListener(Animator.AnimatorListener listener)

Remove a listener that was previously added via addOnShowAnimationListener(AnimatorListener).

void removeOnShrinkAnimationListener(Animator.AnimatorListener listener)

Remove a listener that was previously added via addOnShrinkAnimationListener(AnimatorListener).

void setExtendMotionSpec(MotionSpec spec)

Updates the motion spec for the extend animation.

void setExtendMotionSpecResource(int id)

Updates the motion spec for the extend animation.

void setExtended(boolean extended)

Extends or shrinks the fab depending on the value of .

void setHideMotionSpec(MotionSpec spec)

Updates the motion spec for the hide animation.

void setHideMotionSpecResource(int id)

Updates the motion spec for the hide animation.

void setShowMotionSpec(MotionSpec spec)

Updates the motion spec for the show animation.

void setShowMotionSpecResource(int id)

Updates the motion spec for the show animation.

void setShrinkMotionSpec(MotionSpec spec)

Updates the motion spec for the shrink animation.

void setShrinkMotionSpecResource(int id)

Updates the motion spec for the shrink animation.

void show()

Shows the button.

void show(ExtendedFloatingActionButton.OnChangedCallback callback)

Shows the button.

void shrink(ExtendedFloatingActionButton.OnChangedCallback callback)

Shrinks the FAB to show just the icon.

void shrink()

Shrinks the FAB to show just the icon.

Protected methods

void onAttachedToWindow()

Inherited methods

From class com.google.android.material.button.MaterialButton
From class androidx.appcompat.widget.AppCompatButton
From class android.widget.Button
From class android.widget.TextView
From class android.view.View
From class java.lang.Object
From interface android.widget.Checkable
From interface com.google.android.material.shape.Shapeable
From interface androidx.core.view.TintableBackgroundView
From interface androidx.core.widget.AutoSizeableTextView
From interface android.view.ViewTreeObserver.OnPreDrawListener
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface androidx.coordinatorlayout.widget.CoordinatorLayout.AttachedBehavior

XML attributes

ExtendedFloatingActionButton_extendMotionSpec

Related methods:

ExtendedFloatingActionButton_hideMotionSpec

Related methods:

ExtendedFloatingActionButton_showMotionSpec

Related methods:

ExtendedFloatingActionButton_shrinkMotionSpec

Related methods:

Public constructors

ExtendedFloatingActionButton

ExtendedFloatingActionButton (Context context)

Parameters
context Context

ExtendedFloatingActionButton

ExtendedFloatingActionButton (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

ExtendedFloatingActionButton

ExtendedFloatingActionButton (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

addOnExtendAnimationListener

void addOnExtendAnimationListener (Animator.AnimatorListener listener)

Add a listener that will be invoked when this ExtendedFloatingActionButton is extended. See Animator.AnimatorListener.

Components that add a listener should take care to remove it when finished via removeOnExtendAnimationListener(AnimatorListener).

Parameters
listener Animator.AnimatorListener: listener to add

addOnHideAnimationListener

void addOnHideAnimationListener (Animator.AnimatorListener listener)

Add a listener that will be invoked when this ExtendedFloatingActionButton is hidden. See Animator.AnimatorListener.

Components that add a listener should take care to remove it when finished via removeOnHideAnimationListener(AnimatorListener).

Parameters
listener Animator.AnimatorListener: listener to add

addOnShowAnimationListener

void addOnShowAnimationListener (Animator.AnimatorListener listener)

Add a listener that will be invoked when this ExtendedFloatingActionButton is shown. See Animator.AnimatorListener.

Components that add a listener should take care to remove it when finished via removeOnShowAnimationListener(AnimatorListener).

Parameters
listener Animator.AnimatorListener: listener to add

addOnShrinkAnimationListener

void addOnShrinkAnimationListener (Animator.AnimatorListener listener)

Add a listener that will be invoked when this ExtendedFloatingActionButton is shrunk. See Animator.AnimatorListener.

Components that add a listener should take care to remove it when finished via removeOnShrinkAnimationListener(AnimatorListener).

Parameters
listener Animator.AnimatorListener: listener to add

extend

void extend ()

Extends the FAB to show the text and the icon.

This method will not affect an extended FAB which holds just text and no icon. Also, this method will animate the button show if the view has already been laid out.

extend

void extend (ExtendedFloatingActionButton.OnChangedCallback callback)

Extends the FAB to show the text and the icon.

This method will not affect an extended FAB which holds just text and no icon. Also, this method will animate the button show if the view has already been laid out.

Parameters
callback ExtendedFloatingActionButton.OnChangedCallback: the callback to notify when the FAB is extended

getBehavior

Behavior<ExtendedFloatingActionButton> getBehavior ()

Returns
Behavior<ExtendedFloatingActionButton>

getExtendMotionSpec

MotionSpec getExtendMotionSpec ()

Returns the motion spec for the extend animation.

Returns
MotionSpec

getHideMotionSpec

MotionSpec getHideMotionSpec ()

Returns the motion spec for the hide animation.

Returns
MotionSpec

getShowMotionSpec

MotionSpec getShowMotionSpec ()

Returns the motion spec for the show animation.

Returns
MotionSpec

getShrinkMotionSpec

MotionSpec getShrinkMotionSpec ()

Returns the motion spec for the shrink animation.

Returns
MotionSpec

hide

void hide (ExtendedFloatingActionButton.OnChangedCallback callback)

Hides the button.

This method will animate the button hide if the view has already been laid out.

Parameters
callback ExtendedFloatingActionButton.OnChangedCallback: the callback to notify when this view is hidden

hide

void hide ()

Hides the button.

This method will animate the button hide if the view has already been laid out.

isExtended

boolean isExtended ()

Returns
boolean

removeOnExtendAnimationListener

void removeOnExtendAnimationListener (Animator.AnimatorListener listener)

Remove a listener that was previously added via addOnExtendAnimationListener(AnimatorListener).

Parameters
listener Animator.AnimatorListener: listener to remove

removeOnHideAnimationListener

void removeOnHideAnimationListener (Animator.AnimatorListener listener)

Remove a listener that was previously added via addOnHideAnimationListener(AnimatorListener).

Parameters
listener Animator.AnimatorListener: listener to remove

removeOnShowAnimationListener

void removeOnShowAnimationListener (Animator.AnimatorListener listener)

Remove a listener that was previously added via addOnShowAnimationListener(AnimatorListener).

Parameters
listener Animator.AnimatorListener: listener to remove

removeOnShrinkAnimationListener

void removeOnShrinkAnimationListener (Animator.AnimatorListener listener)

Remove a listener that was previously added via addOnShrinkAnimationListener(AnimatorListener).

Parameters
listener Animator.AnimatorListener: listener to remove

setExtendMotionSpec

void setExtendMotionSpec (MotionSpec spec)

Updates the motion spec for the extend animation.

Related XML Attributes:

Parameters
spec MotionSpec

setExtendMotionSpecResource

void setExtendMotionSpecResource (int id)

Updates the motion spec for the extend animation.

Related XML Attributes:

Parameters
id int

setExtended

void setExtended (boolean extended)

Extends or shrinks the fab depending on the value of .

setHideMotionSpec

void setHideMotionSpec (MotionSpec spec)

Updates the motion spec for the hide animation.

Related XML Attributes:

Parameters
spec MotionSpec

setHideMotionSpecResource

void setHideMotionSpecResource (int id)

Updates the motion spec for the hide animation.

Related XML Attributes:

Parameters
id int

setShowMotionSpec

void setShowMotionSpec (MotionSpec spec)

Updates the motion spec for the show animation.

Related XML Attributes:

Parameters
spec MotionSpec

setShowMotionSpecResource

void setShowMotionSpecResource (int id)

Updates the motion spec for the show animation.

Related XML Attributes:

Parameters
id int

setShrinkMotionSpec

void setShrinkMotionSpec (MotionSpec spec)

Updates the motion spec for the shrink animation.

Related XML Attributes:

Parameters
spec MotionSpec

setShrinkMotionSpecResource

void setShrinkMotionSpecResource (int id)

Updates the motion spec for the shrink animation.

Related XML Attributes:

Parameters
id int

show

void show ()

Shows the button.

This method will animate the button show if the view has already been laid out.

show

void show (ExtendedFloatingActionButton.OnChangedCallback callback)

Shows the button.

This method will animate the button show if the view has already been laid out.

Parameters
callback ExtendedFloatingActionButton.OnChangedCallback: the callback to notify when this view is shown

shrink

void shrink (ExtendedFloatingActionButton.OnChangedCallback callback)

Shrinks the FAB to show just the icon.

This method will not affect an extended FAB which holds just text and no icon. Also, this method will animate the button show if the view has already been laid out.

Parameters
callback ExtendedFloatingActionButton.OnChangedCallback: the callback to notify when the FAB shrank

shrink

void shrink ()

Shrinks the FAB to show just the icon.

This method will not affect an extended FAB which holds just text and no icon. Also, this method will animate the button show if the view has already been laid out.

Protected methods

onAttachedToWindow

void onAttachedToWindow ()