ExtendedFloatingActionButton

public class ExtendedFloatingActionButton extends MaterialButton


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, and the text via setText.

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

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

Summary

Nested types

Behavior designed for use with ExtendedFloatingActionButton instances.

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

Public fields

final Behavior<ExtendedFloatingActionButton>
boolean

Protected fields

ColorStateList

Public constructors

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

Public methods

void
addOnExtendAnimationListener(AnimatorListener listener)

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

void
addOnHideAnimationListener(AnimatorListener listener)

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

void
addOnShowAnimationListener(AnimatorListener listener)

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

void
addOnShrinkAnimationListener(AnimatorListener listener)

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

void

Extends the FAB to show the text and the icon.

void

Extends the FAB to show the text and the icon.

CharSequence
Behavior<ExtendedFloatingActionButton>
MotionSpec

Returns the motion spec for the extend animation.

MotionSpec

Returns the motion spec for the hide animation.

MotionSpec

Returns the motion spec for the show animation.

MotionSpec

Returns the motion spec for the shrink animation.

void

Hides the button.

void

Hides the button.

boolean

Return whether or not animations are enabled.

final boolean
void
removeOnExtendAnimationListener(AnimatorListener listener)

Remove a listener that was previously added via addOnExtendAnimationListener.

void
removeOnHideAnimationListener(AnimatorListener listener)

Remove a listener that was previously added via addOnHideAnimationListener.

void
removeOnShowAnimationListener(AnimatorListener listener)

Remove a listener that was previously added via addOnShowAnimationListener.

void
removeOnShrinkAnimationListener(AnimatorListener listener)

Remove a listener that was previously added via addOnShrinkAnimationListener.

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
setAnimationEnabled(boolean animationEnabled)

Set whether or not animations are enabled.

void

Updates the motion spec for the extend animation.

void

Updates the motion spec for the extend animation.

void
setExtended(boolean extended)

Extends or shrinks the fab depending on the value of {@param extended}.

void

Updates the motion spec for the hide animation.

void

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

Updates the motion spec for the show animation.

void

Updates the motion spec for the show animation.

void

Updates the motion spec for the shrink animation.

void

Updates the motion spec for the shrink animation.

void
setTextColor(int color)
void
setTextColor(ColorStateList colors)
void

Shows the button.

void

Shows the button.

void

Shrinks the FAB to show just the icon.

void

Shrinks the FAB to show just the icon.

Protected methods

void
void
silentlyUpdateTextColor(ColorStateList csl)

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

Inherited Constants

From com.google.android.material.button.MaterialButton
static final int

Gravity used to position the icon at the end of the view.

static final int

Gravity used to position the icon at the start of the view.

static final int

Gravity used to position the icon in the center of the view at the end of the text

static final int

Gravity used to position the icon in the center of the view at the start of the text

static final int

Gravity used to position the icon in the center of the view at the top of the text

static final int

Gravity used to position the icon at the top of the view.

Inherited methods

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

Add a listener that will be invoked when the checked state of this MaterialButton changes.

void

Remove all previously added OnCheckedChangeListeners.

ColorStateList
Mode
int

Gets the corner radius for this button.

Drawable

Gets the icon shown for this button, if present.

int

Gets the icon gravity for this button

int

Gets the padding between the button icon and the button text, if icon is present.

int

Returns the size of the icon if it was set.

ColorStateList

Gets the tint list for the icon shown for this button.

Mode

Gets the tint mode for the icon shown for this button.

int

Gets the bottom inset for this button

int

Gets the top inset for this button

ColorStateList

Gets the ripple color for this button.

ShapeAppearanceModel

Returns the ShapeAppearanceModel used for this MaterialButton's original drawables.

ColorStateList

Gets the stroke color for this button.

int

Gets the stroke width for this button.

boolean

Returns whether this MaterialButton is checkable.

boolean
boolean

Returns whether the optical center feature is enabled.

boolean

Returns whether or not clicking the button will toggle the checked state.

int[]
onCreateDrawableState(int extraSpace)
void
onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent)
void
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onRestoreInstanceState(Parcelable state)
Parcelable
void
onTextChanged(CharSequence charSequence, int i, int i1, int i2)
boolean
void
void

Remove a listener that was previously added via addOnCheckedChangeListener.

void
void
setBackground(Drawable background)
void
setBackgroundColor(int color)
void
setBackgroundDrawable(Drawable background)
void
setBackgroundResource(int backgroundResourceId)
void
setBackgroundTintList(ColorStateList tintList)
void
setBackgroundTintMode(Mode tintMode)
void
setCheckable(boolean checkable)

Sets whether this MaterialButton is checkable.

void
setChecked(boolean checked)
void
setCornerRadius(int cornerRadius)

Sets the corner radius for this button.

void
setCornerRadiusResource(int cornerRadiusResourceId)

Sets the corner radius dimension resource for this button.

void
setElevation(float elevation)
void
setIcon(Drawable icon)

Sets the icon to show for this button.

void

Sets the icon gravity for this button

void
setIconPadding(int iconPadding)

Sets the padding between the button icon and the button text, if icon is present.

void
setIconResource(int iconResourceId)

Sets the icon drawable resource to show for this button.

void
setIconSize(int iconSize)

Sets the width and height of the icon.

void
setIconTint(ColorStateList iconTint)

Sets the tint list for the icon shown for this button.

void
setIconTintMode(Mode iconTintMode)

Sets the tint mode for the icon shown for this button.

void
setIconTintResource(int iconTintResourceId)

Sets the tint list color resource for the icon shown for this button.

void
setInsetBottom(int insetBottom)

Sets the button bottom inset

void
setInsetTop(int insetTop)

Sets the button top inset

void
setOpticalCenterEnabled(boolean opticalCenterEnabled)

Sets whether to enable the optical center feature.

void
setPressed(boolean pressed)
void
setRippleColor(ColorStateList rippleColor)

Sets the ripple color for this button.

void
setRippleColorResource(int rippleColorResourceId)

Sets the ripple color resource for this button.

void

Sets the ShapeAppearanceModel used for this MaterialButton's original drawables.

void
setStrokeColor(ColorStateList strokeColor)

Sets the stroke color for this button.

void
setStrokeColorResource(int strokeColorResourceId)

Sets the stroke color resource for this button.

void
setStrokeWidth(int strokeWidth)

Sets the stroke width for this button.

void
setStrokeWidthResource(int strokeWidthResourceId)

Sets the stroke width dimension resource for this button.

void
setTextAlignment(int textAlignment)
void
setToggleCheckedStateOnClick(boolean toggleCheckedStateOnClick)

Sets whether or not to toggle the button checked state on click.

void
setWidth(int pixels)
void

Public fields

behavior

public final Behavior<ExtendedFloatingActionButton> behavior

isExtended

public boolean isExtended

Protected fields

originalTextCsl

protected ColorStateList originalTextCsl

Public constructors

ExtendedFloatingActionButton

public ExtendedFloatingActionButton(Context context)

ExtendedFloatingActionButton

public ExtendedFloatingActionButton(Context context, AttributeSet attrs)

ExtendedFloatingActionButton

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

Public methods

addOnExtendAnimationListener

public void addOnExtendAnimationListener(AnimatorListener listener)

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

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

Parameters
AnimatorListener listener

listener to add

addOnHideAnimationListener

public void addOnHideAnimationListener(AnimatorListener listener)

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

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

Parameters
AnimatorListener listener

listener to add

addOnShowAnimationListener

public void addOnShowAnimationListener(AnimatorListener listener)

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

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

Parameters
AnimatorListener listener

listener to add

addOnShrinkAnimationListener

public void addOnShrinkAnimationListener(AnimatorListener listener)

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

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

Parameters
AnimatorListener listener

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.

See also
extend

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
ExtendedFloatingActionButton.OnChangedCallback callback

the callback to notify when the FAB is extended

getAccessibilityClassName

public CharSequence getAccessibilityClassName()

getBehavior

public Behavior<ExtendedFloatingActionButton> getBehavior()

getExtendMotionSpec

public MotionSpec getExtendMotionSpec()

Returns the motion spec for the extend animation.

getHideMotionSpec

public MotionSpec getHideMotionSpec()

Returns the motion spec for the hide animation.

getShowMotionSpec

public MotionSpec getShowMotionSpec()

Returns the motion spec for the show animation.

getShrinkMotionSpec

public MotionSpec getShrinkMotionSpec()

Returns the motion spec for the shrink animation.

hide

public void hide()

Hides the button.

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

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
ExtendedFloatingActionButton.OnChangedCallback callback

the callback to notify when this view is hidden

isAnimationEnabled

public boolean isAnimationEnabled()

Return whether or not animations are enabled.

isExtended

public final boolean isExtended()

removeOnExtendAnimationListener

public void removeOnExtendAnimationListener(AnimatorListener listener)

Remove a listener that was previously added via addOnExtendAnimationListener.

Parameters
AnimatorListener listener

listener to remove

removeOnHideAnimationListener

public void removeOnHideAnimationListener(AnimatorListener listener)

Remove a listener that was previously added via addOnHideAnimationListener.

Parameters
AnimatorListener listener

listener to remove

removeOnShowAnimationListener

public void removeOnShowAnimationListener(AnimatorListener listener)

Remove a listener that was previously added via addOnShowAnimationListener.

Parameters
AnimatorListener listener

listener to remove

removeOnShrinkAnimationListener

public void removeOnShrinkAnimationListener(AnimatorListener listener)

Remove a listener that was previously added via addOnShrinkAnimationListener.

Parameters
AnimatorListener listener

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.

setAnimationEnabled

public void setAnimationEnabled(boolean animationEnabled)

Set whether or not animations are enabled.

setExtendMotionSpec

public void setExtendMotionSpec(MotionSpec spec)

Updates the motion spec for the extend animation.

ref com.google.android.material.R.styleable#ExtendedFloatingActionButton_extendMotionSpec

setExtendMotionSpecResource

public void setExtendMotionSpecResource(int id)

Updates the motion spec for the extend animation.

ref com.google.android.material.R.styleable#ExtendedFloatingActionButton_extendMotionSpec

setExtended

public void setExtended(boolean extended)

Extends or shrinks the fab depending on the value of {@param extended}.

setHideMotionSpec

public void setHideMotionSpec(MotionSpec spec)

Updates the motion spec for the hide animation.

ref com.google.android.material.R.styleable#ExtendedFloatingActionButton_hideMotionSpec

setHideMotionSpecResource

public void setHideMotionSpecResource(int id)

Updates the motion spec for the hide animation.

ref com.google.android.material.R.styleable#ExtendedFloatingActionButton_hideMotionSpec

setPadding

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

setPaddingRelative

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

setShowMotionSpec

public void setShowMotionSpec(MotionSpec spec)

Updates the motion spec for the show animation.

ref com.google.android.material.R.styleable#ExtendedFloatingActionButton_showMotionSpec

setShowMotionSpecResource

public void setShowMotionSpecResource(int id)

Updates the motion spec for the show animation.

ref com.google.android.material.R.styleable#ExtendedFloatingActionButton_showMotionSpec

setShrinkMotionSpec

public void setShrinkMotionSpec(MotionSpec spec)

Updates the motion spec for the shrink animation.

ref com.google.android.material.R.styleable#ExtendedFloatingActionButton_shrinkMotionSpec

setShrinkMotionSpecResource

public void setShrinkMotionSpecResource(int id)

Updates the motion spec for the shrink animation.

ref com.google.android.material.R.styleable#ExtendedFloatingActionButton_shrinkMotionSpec

setTextColor

public void setTextColor(int color)

setTextColor

public void setTextColor(ColorStateList colors)

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 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 is true.

Parameters
ExtendedFloatingActionButton.OnChangedCallback callback

the callback to notify when this view is shown

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.

See also
shrink

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
ExtendedFloatingActionButton.OnChangedCallback callback

the callback to notify when the FAB shrank

Protected methods

onAttachedToWindow

protected void onAttachedToWindow()

silentlyUpdateTextColor

protected void silentlyUpdateTextColor(ColorStateList csl)

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