Android APIs
public class

FloatingActionButton

extends ImageView
java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ImageView
       ↳ android.support.design.widget.FloatingActionButton

Class Overview

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 setImageDrawable(Drawable).

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

Summary

Nested Classes
class FloatingActionButton.Behavior Behavior designed for use with FloatingActionButton instances. 
XML Attributes
Attribute Name Related Method Description
android.support.design:fabSize Size for the FAB. 
[Expand]
Inherited XML Attributes
From class android.widget.ImageView
From class android.view.View
[Expand]
Inherited Constants
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
FloatingActionButton(Context context)
FloatingActionButton(Context context, AttributeSet attrs)
FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr)
Public Methods
ColorStateList getBackgroundTintList()
Return the tint applied to the background drawable, if specified.
PorterDuff.Mode getBackgroundTintMode()
Return the blending mode used to apply the tint to the background drawable, if specified.
void hide()
Hides the button.
void jumpDrawablesToCurrentState()
Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.
void setBackgroundDrawable(Drawable background)
This method is deprecated. use setBackground(Drawable) instead
void setBackgroundTintList(ColorStateList tint)
Applies a tint to the background drawable.
void setBackgroundTintMode(PorterDuff.Mode tintMode)
Specifies the blending mode used to apply the tint specified by setBackgroundTintList(ColorStateList)} to the background drawable.
void setRippleColor(int color)
Set the ripple color for this FloatingActionButton.
void show()
Shows the button.
Protected Methods
void drawableStateChanged()
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

[Expand]
Inherited Methods
From class android.widget.ImageView
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

XML Attributes

android.support.design:fabSize

Size for the FAB.

Must be one of the following constant values.

ConstantValueDescription
normal0
mini1

This is a private symbol.

Related Methods

Public Constructors

public FloatingActionButton (Context context)

public FloatingActionButton (Context context, AttributeSet attrs)

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

Public Methods

public ColorStateList getBackgroundTintList ()

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

Returns
  • the tint applied to the background drawable

public PorterDuff.Mode getBackgroundTintMode ()

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

Returns
  • the blending mode used to apply the tint to the background drawable

public void hide ()

Hides the button.

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

public void jumpDrawablesToCurrentState ()

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

Also calls jumpToCurrentState() if there is a StateListAnimator attached to this view.

public void setBackgroundDrawable (Drawable background)

This method is deprecated.
use setBackground(Drawable) instead

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
tint the tint to apply, may be null to clear tint

public void setBackgroundTintMode (PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setBackgroundTintList(ColorStateList)} to the background drawable. The default mode is SRC_IN.

Parameters
tintMode the blending mode used to apply the tint, may be null to clear tint

public void setRippleColor (int color)

Set the ripple color for this FloatingActionButton.

When running on devices with KitKat or below, we draw a fill rather than a ripple.

Parameters
color ARGB color to use for the ripple.

public void show ()

Shows the button.

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

Protected Methods

protected void drawableStateChanged ()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

If the View has a StateListAnimator, it will also be called to run necessary state change animations.

Be sure to call through to the superclass when overriding this function.

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.