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 MaterialButton.setIcon(android.graphics.drawable.Drawable), and the text via TextView.setText(CharSequence).

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

For more information, see the component developer guidance and design guidelines.

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

Inherited constants

Fields

protected ColorStateList originalTextCsl

Inherited fields

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 setAnimateShowBeforeLayout(boolean animateShowBeforeLayout)

Sets whether to enable animation for a call to show show() even if the view has not been laid out yet.

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 setPadding(int left, int top, int right, int bottom)
void setPaddingRelative(int start, int top, int end, int bottom)
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 setTextColor(int color)
void setTextColor(ColorStateList colors)
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()
void silentlyUpdateTextColor(ColorStateList csl)

Update the text color without affecting the original, client-set color.

Inherited methods

XML attributes

ExtendedFloatingActionButton_extendMotionSpec

Related methods:

ExtendedFloatingActionButton_hideMotionSpec

Related methods:

ExtendedFloatingActionButton_showMotionSpec

Related methods:

ExtendedFloatingActionButton_shrinkMotionSpec

Related methods:

Fields

originalTextCsl

protected ColorStateList originalTextCsl

Public constructors

ExtendedFloatingActionButton

public ExtendedFloatingActionButton (Context context)

Parameters
context Context

ExtendedFloatingActionButton

public ExtendedFloatingActionButton (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

ExtendedFloatingActionButton

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

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

addOnExtendAnimationListener

public 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

public 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

public 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

public 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

public 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

public 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

public Behavior<ExtendedFloatingActionButton> getBehavior ()

Returns
Behavior<ExtendedFloatingActionButton>

getExtendMotionSpec

public MotionSpec getExtendMotionSpec ()

Returns the motion spec for the extend animation.

Returns
MotionSpec

getHideMotionSpec

public MotionSpec getHideMotionSpec ()

Returns the motion spec for the hide animation.

Returns
MotionSpec

getShowMotionSpec

public MotionSpec getShowMotionSpec ()

Returns the motion spec for the show animation.

Returns
MotionSpec

getShrinkMotionSpec

public MotionSpec getShrinkMotionSpec ()

Returns the motion spec for the shrink animation.

Returns
MotionSpec

hide

public 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

public void hide ()

Hides the button.

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

isExtended

public final boolean isExtended ()

Returns
boolean

removeOnExtendAnimationListener

public void removeOnExtendAnimationListener (Animator.AnimatorListener listener)

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

Parameters
listener Animator.AnimatorListener: listener to remove

removeOnHideAnimationListener

public void removeOnHideAnimationListener (Animator.AnimatorListener listener)

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

Parameters
listener Animator.AnimatorListener: listener to remove

removeOnShowAnimationListener

public void removeOnShowAnimationListener (Animator.AnimatorListener listener)

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

Parameters
listener Animator.AnimatorListener: listener to remove

removeOnShrinkAnimationListener

public void removeOnShrinkAnimationListener (Animator.AnimatorListener listener)

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

Parameters
listener Animator.AnimatorListener: listener to remove

setAnimateShowBeforeLayout

public void setAnimateShowBeforeLayout (boolean animateShowBeforeLayout)

Sets whether to enable animation for a call to show show() even if the view has not been laid out yet.

This may be set to true if the button is initially hidden but should animate when later shown. The default is false.

Parameters
animateShowBeforeLayout boolean

setExtendMotionSpec

public void setExtendMotionSpec (MotionSpec spec)

Updates the motion spec for the extend animation.

Related XML Attributes:

Parameters
spec MotionSpec

setExtendMotionSpecResource

public void setExtendMotionSpecResource (int id)

Updates the motion spec for the extend animation.

Related XML Attributes:

Parameters
id int

setExtended

public void setExtended (boolean extended)

Extends or shrinks the fab depending on the value of .

setHideMotionSpec

public void setHideMotionSpec (MotionSpec spec)

Updates the motion spec for the hide animation.

Related XML Attributes:

Parameters
spec MotionSpec

setHideMotionSpecResource

public void setHideMotionSpecResource (int id)

Updates the motion spec for the hide animation.

Related XML Attributes:

Parameters
id int

setPadding

public void setPadding (int left, 
                int top, 
                int right, 
                int bottom)

Parameters
left int

top int

right int

bottom int

setPaddingRelative

public void setPaddingRelative (int start, 
                int top, 
                int end, 
                int bottom)

Parameters
start int

top int

end int

bottom int

setShowMotionSpec

public void setShowMotionSpec (MotionSpec spec)

Updates the motion spec for the show animation.

Related XML Attributes:

Parameters
spec MotionSpec

setShowMotionSpecResource

public void setShowMotionSpecResource (int id)

Updates the motion spec for the show animation.

Related XML Attributes:

Parameters
id int

setShrinkMotionSpec

public void setShrinkMotionSpec (MotionSpec spec)

Updates the motion spec for the shrink animation.

Related XML Attributes:

Parameters
spec MotionSpec

setShrinkMotionSpecResource

public void setShrinkMotionSpecResource (int id)

Updates the motion spec for the shrink animation.

Related XML Attributes:

Parameters
id int

setTextColor

public void setTextColor (int color)

Parameters
color int

setTextColor

public void setTextColor (ColorStateList colors)

Parameters
colors ColorStateList

show

public void show ()

Shows the button.

This method will animate the button show if the view has already been laid out, or if setAnimateShowBeforeLayout(boolean) is true.

show

public void show (ExtendedFloatingActionButton.OnChangedCallback callback)

Shows the button.

This method will animate the button show if the view has already been laid out, or if setAnimateShowBeforeLayout(boolean) is true.

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

shrink

public 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

public 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

protected void onAttachedToWindow ()

silentlyUpdateTextColor

protected void silentlyUpdateTextColor (ColorStateList csl)

Update the text color without affecting the original, client-set color.

Parameters
csl ColorStateList