# FloatingActionButton

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/floatingactionbutton/FloatingActionButton.java)

*** ** * ** ***


```
public class FloatingActionButton implements ExpandableTransformationWidget, Shapeable
```

<br />

*** ** * ** ***

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

Floating action buttons come in two sizes: the default and the mini. The size can be controlled with the `fabSize` attribute.

As this class descends from ImageView, you can control the icon which is displayed via `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setImageDrawable(Drawable)`.

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 `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundTintList(ColorStateList)`.

For more information, see the [component developer guidance](https://github.com/material-components/material-components-android/blob/master/docs/components/FloatingActionButton.md) and [design guidelines](https://material.io/components/floating-action-button/overview).

## Summary

| ### Nested types |
|---|
| `protected class https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton.BaseBehavior<T extends https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton>` Behavior designed for use with `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton` instances. |
| `public class https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton.Behavior extends https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton.BaseBehavior` Behavior designed for use with `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton` instances. |
| `public abstract class https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton.OnVisibilityChangedListener` Callback to be invoked when the visibility of a FloatingActionButton changes. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#NO_CUSTOM_SIZE() = 0` Indicates that the `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton` should not have a custom size, and instead that the size should be calculated based on the value set using `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSize(int)` or the ` fabSize` attribute. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_AUTO() = -1` Size which will change based on the window size. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_MINI() = 1` The mini sized button, 40dp. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_NORMAL() = 0` The normal sized button, 56dp. |

| ### Public fields |
|---|---|
| `Mode` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#backgroundTintMode()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#customSize()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#size()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#FloatingActionButton(Context)(Context context)` |
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#FloatingActionButton(Context,AttributeSet)(Context context, AttributeSet attrs)` |
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#FloatingActionButton(Context,AttributeSet,int)( Context context, AttributeSet attrs, int defStyleAttr )` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#addOnHideAnimationListener(AnimatorListener)(AnimatorListener listener)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#addOnShowAnimationListener(AnimatorListener)(AnimatorListener listener)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#addTransformationCallback(com.google.android.material.animation.TransformationCallback<? extends com.google.android.material.floatingactionbutton.FloatingActionButton>)( https://developer.android.com/reference/com/google/android/material/animation/TransformationCallback<https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton> listener )` Add a `https://developer.android.com/reference/com/google/android/material/animation/TransformationCallback` which can watch for changes to this view. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#clearCustomSize()()` Clears the custom size for this `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton`. |
| `https://developer.android.com/reference/java/lang/CharSequence` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getAccessibilityClassName()()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getBackgroundTintList()()` Returns the tint applied to the background drawable, if specified. |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getBackgroundTintMode()()` Returns the blending mode used to apply the tint to the background drawable, if specified. |
| `Behavior<FloatingActionButton>` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getBehavior()()` |
| `float` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getCompatElevation()()` Returns the backward compatible elevation of the FloatingActionButton. |
| `float` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getCompatHoveredFocusedTranslationZ()()` Returns the backward compatible hovered/focused translationZ of the FloatingActionButton. |
| `float` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getCompatPressedTranslationZ()()` Returns the backward compatible pressed translationZ of the FloatingActionButton. |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getContentBackground()()` Returns the FloatingActionButton's background, minus any compatible shadow implementation. |
| `boolean` | `[getContentRect](https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getContentRect(Rect))(Rect rect)` **This method is deprecated.** prefer `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getMeasuredContentRect(Rect)` instead, so you don't need to handle the case where the view isn't laid out. <br /> |
| `int` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getCustomSize()()` Returns the custom size for this `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton`. |
| `int` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getExpandedComponentIdHint()()` Returns the expanded component id hint. |
| `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getHideMotionSpec()()` Returns the motion spec for the hide animation. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getMeasuredContentRect(Rect)(Rect rect)` Return in `rect` the bounds of the actual floating action button content in view-local coordinates. |
| `int` | `[getRippleColor](https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getRippleColor())()` **This method is deprecated.** Use `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getRippleColorStateList()` instead. <br /> |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getRippleColorStateList()()` Returns the ripple color for this button. |
| `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getShapeAppearanceModel()()` Returns the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` for this `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton`. |
| `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getShowMotionSpec()()` Returns the motion spec for the show animation. |
| `int` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getSize()()` Returns the chosen size for this button. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getSupportBackgroundTintList()()` Compat method to support TintableBackgroundView. |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getSupportBackgroundTintMode()()` Compat method to support TintableBackgroundView. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getSupportImageTintList()()` |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getSupportImageTintMode()()` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getUseCompatPadding()()` Returns whether FloatingActionButton will add inner padding on platforms Lollipop and after. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#hide()()` Hides the button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#hide(com.google.android.material.floatingactionbutton.FloatingActionButton.OnVisibilityChangedListener)(https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton.OnVisibilityChangedListener listener)` Hides the button. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#isExpanded()()` Returns whether this widget is expanded. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#isOrWillBeHidden()()` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#isOrWillBeShown()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#jumpDrawablesToCurrentState()()` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#onTouchEvent(MotionEvent)(MotionEvent ev)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#removeOnHideAnimationListener(AnimatorListener)(AnimatorListener listener)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#removeOnShowAnimationListener(AnimatorListener)(AnimatorListener listener)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#removeTransformationCallback(com.google.android.material.animation.TransformationCallback<? extends com.google.android.material.floatingactionbutton.FloatingActionButton>)( https://developer.android.com/reference/com/google/android/material/animation/TransformationCallback<https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton> listener )` Remove the `https://developer.android.com/reference/com/google/android/material/animation/TransformationCallback` from this view. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundColor(int)(int color)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundDrawable(Drawable)(Drawable background)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundResource(int)(int resid)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundTintList(ColorStateList)(ColorStateList tint)` Applies a tint to the background drawable. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundTintMode(PorterDuff.Mode)(Mode tintMode)` Specifies the blending mode used to apply the tint specified by `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundTintList(ColorStateList)`} to the background drawable. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setClickable(boolean)(boolean clickable)` Sets the clickable state of this view. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setCompatElevation(float)(float elevation)` Updates the backward compatible elevation of the FloatingActionButton. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setCompatElevationResource(int)(int id)` Updates the backward compatible elevation of the FloatingActionButton. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setCompatHoveredFocusedTranslationZ(float)(float translationZ)` Updates the backward compatible hovered/focused translationZ of the FloatingActionButton. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setCompatHoveredFocusedTranslationZResource(int)(int id)` Updates the backward compatible hovered/focused translationZ of the FloatingActionButton. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setCompatPressedTranslationZ(float)(float translationZ)` Updates the backward compatible pressed translationZ of the FloatingActionButton. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setCompatPressedTranslationZResource(int)(int id)` Updates the backward compatible pressed translationZ of the FloatingActionButton. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setContentDescription(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence contentDescription)` Sets the content description for this view. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setCustomSize(int)(int size)` Sets the size of the button to be a custom value in pixels. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setElevation(float)(float elevation)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setEnsureMinTouchTargetSize(boolean)(boolean flag)` Sets whether this FloatingActionButton should expand its bounds (if needed) to meet the minimum touch target size. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setExpanded(boolean)(boolean expanded)` Sets the expanded state on this widget. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setExpandedComponentIdHint(int)(int expandedComponentIdHint)` Sets the expanded component id hint, which may be used by a Behavior to determine whether it should handle this widget's state change. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setHideMotionSpec(com.google.android.material.animation.MotionSpec)(https://developer.android.com/reference/com/google/android/material/animation/MotionSpec spec)` Updates the motion spec for the hide animation. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setHideMotionSpecResource(int)(int id)` Updates the motion spec for the hide animation. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setImageDrawable(Drawable)(Drawable drawable)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setImageResource(int)(int resId)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setMaxImageSize(int)(int imageSize)` Sets the max image size for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setRippleColor(ColorStateList)(ColorStateList color)` Sets the ripple color for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setRippleColor(int)(int color)` Sets the ripple color for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setScaleX(float)(float scaleX)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setScaleY(float)(float scaleY)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setShapeAppearanceModel(com.google.android.material.shape.ShapeAppearanceModel)(https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel shapeAppearance)` Sets the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` for this `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton`. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setShowMotionSpec(com.google.android.material.animation.MotionSpec)(https://developer.android.com/reference/com/google/android/material/animation/MotionSpec spec)` Updates the motion spec for the show animation. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setShowMotionSpecResource(int)(int id)` Updates the motion spec for the show animation. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSize(int)(int size)` Sets the size of the button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSupportBackgroundTintList(ColorStateList)(ColorStateList tint)` Compat method to support TintableBackgroundView. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSupportBackgroundTintMode(Mode)(Mode tintMode)` Compat method to support TintableBackgroundView. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSupportImageTintList(ColorStateList)(ColorStateList tint)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSupportImageTintMode(Mode)(Mode tintMode)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setTranslationX(float)(float translationX)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setTranslationY(float)(float translationY)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setTranslationZ(float)(float translationZ)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setUseCompatPadding(boolean)(boolean useCompatPadding)` Set whether FloatingActionButton should add inner padding on platforms Lollipop and after, to ensure consistent dimensions on all platforms. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setVisibility(int)(int visibility)` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#shouldEnsureMinTouchTargetSize()()` Returns whether this fab will expand its bounds (if needed) to meet the minimum touch target size. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#show()()` Shows the button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#show(com.google.android.material.floatingactionbutton.FloatingActionButton.OnVisibilityChangedListener)(https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton.OnVisibilityChangedListener listener)` Shows the button. |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#drawableStateChanged()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#onAttachedToWindow()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#onDetachedFromWindow()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#onMeasure(int,int)(int widthMeasureSpec, int heightMeasureSpec)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#onRestoreInstanceState(Parcelable)(Parcelable state)` |
| `Parcelable` | `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#onSaveInstanceState()()` |

## Constants

### NO_CUSTOM_SIZE

```
public static final int NO_CUSTOM_SIZE = 0
```

Indicates that the `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton` should not have a custom size, and instead that the size should be calculated based on the value set using `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSize(int)` or the `
fabSize` attribute. Instead of using this constant directly, you can call the `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#clearCustomSize()` method.

### SIZE_AUTO

```
public static final int SIZE_AUTO = -1
```

Size which will change based on the window size. For small sized windows (largest screen dimension \<470dp) this will select a mini sized button (`https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_MINI()`), and for larger sized windows it will select a normal sized button (`https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_NORMAL()`).

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSize(int)` |   |

### SIZE_MINI

```
public static final int SIZE_MINI = 1
```

The mini sized button, 40dp. Will always be smaller than `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_NORMAL()`.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSize(int)` |   |

### SIZE_NORMAL

```
public static final int SIZE_NORMAL = 0
```

The normal sized button, 56dp. Will always be larger than `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_MINI()`.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSize(int)` |   |

## Public fields

### backgroundTintMode

```
public Mode backgroundTintMode
```

### customSize

```
public int customSize
```

### size

```
public int size
```

## Public constructors

### FloatingActionButton

```
public FloatingActionButton(Context context)
```

### FloatingActionButton

```
public FloatingActionButton(Context context, AttributeSet attrs)
```

### FloatingActionButton

```
public FloatingActionButton(
    Context context,
    AttributeSet attrs,
    int defStyleAttr
)
```

## Public methods

### addOnHideAnimationListener

```
public void addOnHideAnimationListener(AnimatorListener listener)
```

### addOnShowAnimationListener

```
public void addOnShowAnimationListener(AnimatorListener listener)
```

### addTransformationCallback

```
public void addTransformationCallback(
    TransformationCallback<FloatingActionButton> listener
)
```

Add a `https://developer.android.com/reference/com/google/android/material/animation/TransformationCallback` which can watch for changes to this view.

### clearCustomSize

```
public void clearCustomSize()
```

Clears the custom size for this `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton`.

If called, custom sizing will not be used and the size will be calculated based on the value set using `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSize(int)` or the `fabSize` attribute

### getAccessibilityClassName

```
public CharSequence getAccessibilityClassName()
```

### getBackgroundTintList

```
public ColorStateList getBackgroundTintList()
```

Returns the tint applied to the background drawable, if specified.

| Returns |
|---|---|
| `ColorStateList` | the tint applied to the background drawable |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundTintList(ColorStateList)` |   |

### getBackgroundTintMode

```
public Mode getBackgroundTintMode()
```

Returns the blending mode used to apply the tint to the background drawable, if specified.

| Returns |
|---|---|
| `Mode` | the blending mode used to apply the tint to the background drawable |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundTintMode(PorterDuff.Mode)` |   |

### getBehavior

```
public Behavior<FloatingActionButton> getBehavior()
```

### getCompatElevation

```
public float getCompatElevation()
```

Returns the backward compatible elevation of the FloatingActionButton.

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

| Returns |
|---|---|
| `float` | the backward compatible elevation in pixels. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setCompatElevation(float)` |   |

### getCompatHoveredFocusedTranslationZ

```
public float getCompatHoveredFocusedTranslationZ()
```

Returns the backward compatible hovered/focused translationZ of the FloatingActionButton.

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

| Returns |
|---|---|
| `float` | the backward compatible hovered/focused translationZ in pixels. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setCompatHoveredFocusedTranslationZ(float)` |   |

### getCompatPressedTranslationZ

```
public float getCompatPressedTranslationZ()
```

Returns the backward compatible pressed translationZ of the FloatingActionButton.

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

| Returns |
|---|---|
| `float` | the backward compatible pressed translationZ in pixels. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setCompatPressedTranslationZ(float)` |   |

### getContentBackground

```
public Drawable getContentBackground()
```

Returns the FloatingActionButton's background, minus any compatible shadow implementation.

### getContentRect

```
public boolean [getContentRect](https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getContentRect(Rect))(Rect rect)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> prefer `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getMeasuredContentRect(Rect)` instead, so you don't need to handle the case where the view isn't laid out.

Return in `rect` the bounds of the actual floating action button content in view-local coordinates. This is defined as anything within any visible shadow.

| Returns |
|---|---|
| `boolean` | true if this view actually has been laid out and has a content rect, else false. |

### getCustomSize

```
public int getCustomSize()
```

Returns the custom size for this `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton`.

| Returns |
|---|---|
| `int` | size in pixels, or `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#NO_CUSTOM_SIZE()` |

### getExpandedComponentIdHint

```
public int getExpandedComponentIdHint()
```

Returns the expanded component id hint.

### getHideMotionSpec

```
public MotionSpec getHideMotionSpec()
```

Returns the motion spec for the hide animation.

### getMeasuredContentRect

```
public void getMeasuredContentRect(Rect rect)
```

Return in `rect` the bounds of the actual floating action button content in view-local coordinates. This is defined as anything within any visible shadow.

### getRippleColor

```
public int [getRippleColor](https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getRippleColor())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getRippleColorStateList()` instead.

Returns the ripple color for this button.

| Returns |
|---|---|
| `int` | the ARGB color used for the ripple |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setRippleColor(int)` |   |

### getRippleColorStateList

```
public ColorStateList getRippleColorStateList()
```

Returns the ripple color for this button.

| Returns |
|---|---|
| `ColorStateList` | the color state list used for the ripple |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setRippleColor(ColorStateList)` |   |

### getShapeAppearanceModel

```
public ShapeAppearanceModel getShapeAppearanceModel()
```

Returns the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` for this `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton`.

### getShowMotionSpec

```
public MotionSpec getShowMotionSpec()
```

Returns the motion spec for the show animation.

### getSize

```
public int getSize()
```

Returns the chosen size for this button.

| Returns |
|---|---|
| `int` | one of `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_NORMAL()`, `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_MINI()` or `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_AUTO()` |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSize(int)` |   |

### getSupportBackgroundTintList

```
public ColorStateList getSupportBackgroundTintList()
```

Compat method to support TintableBackgroundView. Use `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getBackgroundTintList()` directly instead.

### getSupportBackgroundTintMode

```
public Mode getSupportBackgroundTintMode()
```

Compat method to support TintableBackgroundView. Use `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getBackgroundTintMode()` directly instead.

### getSupportImageTintList

```
public ColorStateList getSupportImageTintList()
```

### getSupportImageTintMode

```
public Mode getSupportImageTintMode()
```

### getUseCompatPadding

```
public boolean getUseCompatPadding()
```

Returns whether FloatingActionButton will add inner padding on platforms Lollipop and after.

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

| Returns |
|---|---|
| `boolean` | true if FloatingActionButton is adding inner padding on platforms Lollipop and after, to ensure consistent dimensions on all platforms. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setUseCompatPadding(boolean)` |   |

### 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(FloatingActionButton.OnVisibilityChangedListener listener)
```

Hides the button.

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton.OnVisibilityChangedListener listener` | the listener to notify when this view is hidden |

### isExpanded

```
public boolean isExpanded()
```

Returns whether this widget is expanded.

Implementations should call `https://developer.android.com/reference/com/google/android/material/expandable/ExpandableWidgetHelper#isExpanded()`.

### isOrWillBeHidden

```
public boolean isOrWillBeHidden()
```

### isOrWillBeShown

```
public boolean isOrWillBeShown()
```

### jumpDrawablesToCurrentState

```
public void jumpDrawablesToCurrentState()
```

### onTouchEvent

```
public boolean onTouchEvent(MotionEvent ev)
```

### removeOnHideAnimationListener

```
public void removeOnHideAnimationListener(AnimatorListener listener)
```

### removeOnShowAnimationListener

```
public void removeOnShowAnimationListener(AnimatorListener listener)
```

### removeTransformationCallback

```
public void removeTransformationCallback(
    TransformationCallback<FloatingActionButton> listener
)
```

Remove the `https://developer.android.com/reference/com/google/android/material/animation/TransformationCallback` from this view. It will no longer receive updates when this view is transformed.

### setBackgroundColor

```
public void setBackgroundColor(int color)
```

### setBackgroundDrawable

```
public void setBackgroundDrawable(Drawable background)
```

### setBackgroundResource

```
public void setBackgroundResource(int resid)
```

### setBackgroundTintList

```
public void setBackgroundTintList(ColorStateList tint)
```

Applies a tint to the background drawable. Does not modify the current tint mode, which is SRC_IN by default.

| Parameters |
|---|---|
| `ColorStateList tint` | the tint to apply, may be `null` to clear tint |

### setBackgroundTintMode

```
public void setBackgroundTintMode(Mode tintMode)
```

Specifies the blending mode used to apply the tint specified by `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundTintList(ColorStateList)`} to the background drawable. The default mode is SRC_IN.

| Parameters |
|---|---|
| `Mode tintMode` | the blending mode used to apply the tint, may be `null` to clear tint |

### setClickable

```
public void setClickable(boolean clickable)
```

Sets the clickable state of this view.

On API 26 (Android O) and above, if the view is not clickable, this method also clears the tooltip text to prevent the view from consuming touch events.

### setCompatElevation

```
public void setCompatElevation(float elevation)
```

Updates the backward compatible elevation of the FloatingActionButton.

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

| Parameters |
|---|---|
| `float elevation` | The backward compatible elevation in pixels. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getCompatElevation()` |   |
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setUseCompatPadding(boolean)` |   |

### setCompatElevationResource

```
public void setCompatElevationResource(int id)
```

Updates the backward compatible elevation of the FloatingActionButton.

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

| Parameters |
|---|---|
| `int id` | The resource id of the backward compatible elevation. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getCompatElevation()` |   |
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setUseCompatPadding(boolean)` |   |

### setCompatHoveredFocusedTranslationZ

```
public void setCompatHoveredFocusedTranslationZ(float translationZ)
```

Updates the backward compatible hovered/focused translationZ of the FloatingActionButton.

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

| Parameters |
|---|---|
| `float translationZ` | The backward compatible hovered/focused translationZ in pixels. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getCompatHoveredFocusedTranslationZ()` |   |
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setUseCompatPadding(boolean)` |   |

### setCompatHoveredFocusedTranslationZResource

```
public void setCompatHoveredFocusedTranslationZResource(int id)
```

Updates the backward compatible hovered/focused translationZ of the FloatingActionButton.

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

| Parameters |
|---|---|
| `int id` | The resource id of the backward compatible hovered/focused translationZ. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getCompatHoveredFocusedTranslationZ()` |   |
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setUseCompatPadding(boolean)` |   |

### setCompatPressedTranslationZ

```
public void setCompatPressedTranslationZ(float translationZ)
```

Updates the backward compatible pressed translationZ of the FloatingActionButton.

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

| Parameters |
|---|---|
| `float translationZ` | The backward compatible pressed translationZ in pixels. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getCompatPressedTranslationZ()` |   |
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setUseCompatPadding(boolean)` |   |

### setCompatPressedTranslationZResource

```
public void setCompatPressedTranslationZResource(int id)
```

Updates the backward compatible pressed translationZ of the FloatingActionButton.

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

| Parameters |
|---|---|
| `int id` | The resource id of the backward compatible pressed translationZ. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getCompatPressedTranslationZ()` |   |
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setUseCompatPadding(boolean)` |   |

### setContentDescription

```
public void setContentDescription(CharSequence contentDescription)
```

Sets the content description for this view.

On API 26 (Android O) and above, this method also sets the tooltip text to the content description if appropriate.

### setCustomSize

```
public void setCustomSize(int size)
```

Sets the size of the button to be a custom value in pixels.

If you've set a custom size and would like to clear it, you can use the `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#clearCustomSize()` method. If called, custom sizing will not be used and the size will be calculated based on the value set using `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setSize(int)` or the `fabSize` attribute.

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

| Parameters |
|---|---|
| `int size` | preferred size in pixels, or `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#NO_CUSTOM_SIZE()` |

### setElevation

```
public void setElevation(float elevation)
```

### setEnsureMinTouchTargetSize

```
public void setEnsureMinTouchTargetSize(boolean flag)
```

Sets whether this FloatingActionButton should expand its bounds (if needed) to meet the minimum touch target size.

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

### setExpanded

```
public boolean setExpanded(boolean expanded)
```

Sets the expanded state on this widget.

Implementations should call `https://developer.android.com/reference/com/google/android/material/expandable/ExpandableWidgetHelper#setExpanded(boolean)`.

| Returns |
|---|---|
| `boolean` | true if the expanded state changed as a result of this call. |

### setExpandedComponentIdHint

```
public void setExpandedComponentIdHint(int expandedComponentIdHint)
```

Sets the expanded component id hint, which may be used by a Behavior to determine whether it should handle this widget's state change.

### setHideMotionSpec

```
public void setHideMotionSpec(MotionSpec spec)
```

Updates the motion spec for the hide animation.

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

### setHideMotionSpecResource

```
public void setHideMotionSpecResource(int id)
```

Updates the motion spec for the hide animation.

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

### setImageDrawable

```
public void setImageDrawable(Drawable drawable)
```

### setImageResource

```
public void setImageResource(int resId)
```

### setMaxImageSize

```
public void setMaxImageSize(int imageSize)
```

Sets the max image size for this button.

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

| Parameters |
|---|---|
| `int imageSize` | maximum icon image size |

### setRippleColor

```
public void setRippleColor(ColorStateList color)
```

Sets the ripple color for this button.

When running on devices with KitKat, we draw this color as a filled circle rather than a ripple.

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

| Parameters |
|---|---|
| `ColorStateList color` | color state list to use for the ripple |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getRippleColor()` |   |

### setRippleColor

```
public void setRippleColor(int color)
```

Sets the ripple color for this button.

When running on devices with KitKat, we draw this color as a filled circle rather than a ripple.

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

| Parameters |
|---|---|
| `int color` | ARGB color to use for the ripple |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getRippleColor()` |   |

### setScaleX

```
public void setScaleX(float scaleX)
```

### setScaleY

```
public void setScaleY(float scaleY)
```

### setShapeAppearanceModel

```
public void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearance)
```

Sets the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` for this `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton`.

### setShowMotionSpec

```
public void setShowMotionSpec(MotionSpec spec)
```

Updates the motion spec for the show animation.

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

### setShowMotionSpecResource

```
public void setShowMotionSpecResource(int id)
```

Updates the motion spec for the show animation.

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

### setSize

```
public void setSize(int size)
```

Sets the size of the button.

The options relate to the options available on the material design specification. `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_NORMAL()` is larger than `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_MINI()`. `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_AUTO()` will choose an appropriate size based on the screen size.

Calling this method will turn off custom sizing (see `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setCustomSize(int)`) if it was previously on.

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

| Parameters |
|---|---|
| `int size` | one of `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_NORMAL()`, `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_MINI()` or `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#SIZE_AUTO()` |

### setSupportBackgroundTintList

```
public void setSupportBackgroundTintList(ColorStateList tint)
```

Compat method to support TintableBackgroundView. Use `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundTintList(ColorStateList)` directly instead.

### setSupportBackgroundTintMode

```
public void setSupportBackgroundTintMode(Mode tintMode)
```

Compat method to support TintableBackgroundView. Use `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setBackgroundTintMode(PorterDuff.Mode)` directly instead.

### setSupportImageTintList

```
public void setSupportImageTintList(ColorStateList tint)
```

### setSupportImageTintMode

```
public void setSupportImageTintMode(Mode tintMode)
```

### setTranslationX

```
public void setTranslationX(float translationX)
```

### setTranslationY

```
public void setTranslationY(float translationY)
```

### setTranslationZ

```
public void setTranslationZ(float translationZ)
```

### setUseCompatPadding

```
public void setUseCompatPadding(boolean useCompatPadding)
```

Set whether FloatingActionButton should add inner padding on platforms Lollipop and after, to ensure consistent dimensions on all platforms.

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

| Parameters |
|---|---|
| `boolean useCompatPadding` | true if FloatingActionButton is adding inner padding on platforms Lollipop and after, to ensure consistent dimensions on all platforms. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#getUseCompatPadding()` |   |

### setVisibility

```
public void setVisibility(int visibility)
```

### shouldEnsureMinTouchTargetSize

```
public boolean shouldEnsureMinTouchTargetSize()
```

Returns whether this fab will expand its bounds (if needed) to meet the minimum touch target size.

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

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton#setEnsureMinTouchTargetSize(boolean)` |   |

### show

```
public void show()
```

Shows the button.

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

### show

```
public void show(FloatingActionButton.OnVisibilityChangedListener listener)
```

Shows the button.

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton.OnVisibilityChangedListener listener` | the listener to notify when this view is shown |

## Protected methods

### drawableStateChanged

```
protected void drawableStateChanged()
```

### onAttachedToWindow

```
protected void onAttachedToWindow()
```

### onDetachedFromWindow

```
protected void onDetachedFromWindow()
```

### onMeasure

```
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
```

### onRestoreInstanceState

```
protected void onRestoreInstanceState(Parcelable state)
```

### onSaveInstanceState

```
protected Parcelable onSaveInstanceState()
```