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.OnChangedListener

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)
void addOnHideAnimationListener(Animator.AnimatorListener listener)
void addOnShowAnimationListener(Animator.AnimatorListener listener)
void addOnShrinkAnimationListener(Animator.AnimatorListener listener)
void extend()

Extends the FAB to show the text and the icon.

void extend(ExtendedFloatingActionButton.OnChangedListener listener)

Extends the FAB to show the text and the icon.

void extend(boolean animate)

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.

final int getUserSetVisibility()
void hide(ExtendedFloatingActionButton.OnChangedListener listener)

Hides the button.

void hide(boolean animate)

Hides the button.

void hide()

Hides the button.

final boolean isExtended()
void removeOnExtendAnimationListener(Animator.AnimatorListener listener)
void removeOnHideAnimationListener(Animator.AnimatorListener listener)
void removeOnShowAnimationListener(Animator.AnimatorListener listener)
void removeOnShrinkAnimationListener(Animator.AnimatorListener listener)
void setCornerRadius(int cornerRadius)

Sets the corner radius for this button.

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 setHideMotionSpec(MotionSpec spec)

Updates the motion spec for the hide animation.

void setHideMotionSpecResource(int id)

Updates the motion spec for the hide animation.

void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel)

Sets the ShapeAppearanceModel that defines the component's MaterialShapeDrawable's shape using shapeAppearanceModel.

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 setVisibility(int visibility)
void show()

Shows the button.

void show(boolean animate)

Shows the button.

void show(ExtendedFloatingActionButton.OnChangedListener listener)

Shows the button.

void shrink(ExtendedFloatingActionButton.OnChangedListener listener)

Shrinks the FAB to show just the icon.

void shrink(boolean animate)

Shrinks the FAB to show just the icon.

void shrink()

Shrinks the FAB to show just the icon.

Protected methods

void onAttachedToWindow()
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

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)

Parameters
listener Animator.AnimatorListener

addOnHideAnimationListener

void addOnHideAnimationListener (Animator.AnimatorListener listener)

Parameters
listener Animator.AnimatorListener

addOnShowAnimationListener

void addOnShowAnimationListener (Animator.AnimatorListener listener)

Parameters
listener Animator.AnimatorListener

addOnShrinkAnimationListener

void addOnShrinkAnimationListener (Animator.AnimatorListener listener)

Parameters
listener Animator.AnimatorListener

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.

See also:

extend

void extend (ExtendedFloatingActionButton.OnChangedListener listener)

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
listener ExtendedFloatingActionButton.OnChangedListener: the listener to notify when the FAB is extended

extend

void extend (boolean animate)

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.

Parameters
animate boolean: whether or not the extending is animated

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

getUserSetVisibility

int getUserSetVisibility ()

Returns
int

hide

void hide (ExtendedFloatingActionButton.OnChangedListener listener)

Hides the button.

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

Parameters
listener ExtendedFloatingActionButton.OnChangedListener: the listener to notify when this view is hidden

hide

void hide (boolean animate)

Hides the button.

Parameters
animate boolean: whether or not the button's hiding is animated

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)

Parameters
listener Animator.AnimatorListener

removeOnHideAnimationListener

void removeOnHideAnimationListener (Animator.AnimatorListener listener)

Parameters
listener Animator.AnimatorListener

removeOnShowAnimationListener

void removeOnShowAnimationListener (Animator.AnimatorListener listener)

Parameters
listener Animator.AnimatorListener

removeOnShrinkAnimationListener

void removeOnShrinkAnimationListener (Animator.AnimatorListener listener)

Parameters
listener Animator.AnimatorListener

setCornerRadius

void setCornerRadius (int cornerRadius)

Sets the corner radius for this button.

Parameters
cornerRadius int: Corner radius for this button.

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

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

setShapeAppearanceModel

void setShapeAppearanceModel (ShapeAppearanceModel shapeAppearanceModel)

Sets the ShapeAppearanceModel that defines the component's MaterialShapeDrawable's shape using shapeAppearanceModel.

Parameters
shapeAppearanceModel ShapeAppearanceModel

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

setVisibility

void setVisibility (int visibility)

Parameters
visibility 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 (boolean animate)

Shows the button.

Parameters
animate boolean: whether or not the button's showing is animated

show

void show (ExtendedFloatingActionButton.OnChangedListener listener)

Shows the button.

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

Parameters
listener ExtendedFloatingActionButton.OnChangedListener: the listener to notify when this view is shown

shrink

void shrink (ExtendedFloatingActionButton.OnChangedListener listener)

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
listener ExtendedFloatingActionButton.OnChangedListener: the listener to notify when the FAB shrank

shrink

void shrink (boolean animate)

Shrinks the FAB to show just the icon.

This method will not affect an extended FAB which holds just text and no icon.

Parameters
animate boolean: whether or not the shrinking is animated

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.

See also:

Protected methods

onAttachedToWindow

void onAttachedToWindow ()

onMeasure

void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int