Skip to content

Most visited

Recently visited

navigation
added in version 24.1.0
belongs to Maven artifact com.android.support:design:27.0.0

FloatingActionButton

public class FloatingActionButton
extends ImageButton

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


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. 

class FloatingActionButton.OnVisibilityChangedListener

Callback to be invoked when the visibility of a FloatingActionButton changes. 

XML attributes

FloatingActionButton_elevation  
FloatingActionButton_fabSize  
FloatingActionButton_rippleColor  
FloatingActionButton_useCompatPadding  

Constants

int SIZE_AUTO

Size which will change based on the window size.

int SIZE_MINI

The mini sized button.

int SIZE_NORMAL

The normal sized button.

Inherited constants

From class android.view.View

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()

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

PorterDuff.Mode getBackgroundTintMode()

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

float getCompatElevation()

Returns the backward compatible elevation of the FloatingActionButton.

Drawable getContentBackground()

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

boolean getContentRect(Rect rect)

Return in rect the bounds of the actual floating action button content in view-local coordinates.

int getRippleColor()

Returns the ripple color for this button.

int getSize()

Returns the chosen size for this button.

boolean getUseCompatPadding()

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

void hide()

Hides the button.

void hide(FloatingActionButton.OnVisibilityChangedListener listener)

Hides the button.

void jumpDrawablesToCurrentState()
boolean onTouchEvent(MotionEvent ev)
void setBackgroundColor(int color)
void setBackgroundDrawable(Drawable background)
void setBackgroundResource(int resid)
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 setCompatElevation(float elevation)

Updates the backward compatible elevation of the FloatingActionButton.

void setImageResource(int resId)
void setRippleColor(int color)

Sets the ripple color for this button.

void setSize(int size)

Sets the size of the button.

void setUseCompatPadding(boolean useCompatPadding)

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

void setVisibility(int visibility)
void show(FloatingActionButton.OnVisibilityChangedListener listener)

Shows the button.

void show()

Shows the button.

Protected methods

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

Inherited methods

From class android.widget.ImageButton
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

FloatingActionButton_elevation

Related methods:

FloatingActionButton_fabSize

Related methods:

FloatingActionButton_rippleColor

Related methods:

FloatingActionButton_useCompatPadding

Related methods:

Constants

SIZE_AUTO

added in version 24.1.0
int SIZE_AUTO

Size which will change based on the window size. For small sized windows (largest screen dimension < 470dp) this will select a small sized button, and for larger sized windows it will select a larger size.

See also:

Constant Value: -1 (0xffffffff)

SIZE_MINI

added in version 24.1.0
int SIZE_MINI

The mini sized button. Will always been smaller than SIZE_NORMAL.

See also:

Constant Value: 1 (0x00000001)

SIZE_NORMAL

added in version 24.1.0
int SIZE_NORMAL

The normal sized button. Will always been larger than SIZE_MINI.

See also:

Constant Value: 0 (0x00000000)

Public constructors

FloatingActionButton

added in version 24.1.0
FloatingActionButton (Context context)

Parameters
context Context

FloatingActionButton

added in version 24.1.0
FloatingActionButton (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

FloatingActionButton

added in version 24.1.0
FloatingActionButton (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

getBackgroundTintList

ColorStateList getBackgroundTintList ()

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

Returns
ColorStateList the tint applied to the background drawable

See also:

getBackgroundTintMode

PorterDuff.Mode getBackgroundTintMode ()

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

Returns
PorterDuff.Mode the blending mode used to apply the tint to the background drawable

See also:

getCompatElevation

added in version 24.1.0
float getCompatElevation ()

Returns the backward compatible elevation of the FloatingActionButton.

Related XML Attributes:

Returns
float the backward compatible elevation in pixels.

See also:

getContentBackground

added in version 24.1.0
Drawable getContentBackground ()

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

Returns
Drawable

getContentRect

added in version 24.1.0
boolean getContentRect (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.

Parameters
rect Rect

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

getRippleColor

added in version 25.1.0
int getRippleColor ()

Returns the ripple color for this button.

Returns
int the ARGB color used for the ripple

See also:

getSize

added in version 24.1.0
int getSize ()

Returns the chosen size for this button.

Returns
int one of SIZE_NORMAL, SIZE_MINI or SIZE_AUTO

See also:

getUseCompatPadding

added in version 24.1.0
boolean getUseCompatPadding ()

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

Related XML Attributes:

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

See also:

hide

added in version 24.1.0
void hide ()

Hides the button.

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

hide

added in version 24.1.0
void hide (FloatingActionButton.OnVisibilityChangedListener listener)

Hides the button.

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

Parameters
listener FloatingActionButton.OnVisibilityChangedListener: the listener to notify when this view is hidden

jumpDrawablesToCurrentState

void jumpDrawablesToCurrentState ()

onTouchEvent

boolean onTouchEvent (MotionEvent ev)

Parameters
ev MotionEvent

Returns
boolean

setBackgroundColor

void setBackgroundColor (int color)

Parameters
color int

setBackgroundDrawable

added in version 26.1.0
void setBackgroundDrawable (Drawable background)

Parameters
background Drawable

setBackgroundResource

void setBackgroundResource (int resid)

Parameters
resid int

setBackgroundTintList

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

setBackgroundTintMode

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 PorterDuff.Mode: the blending mode used to apply the tint, may be null to clear tint

setCompatElevation

added in version 24.1.0
void setCompatElevation (float elevation)

Updates the backward compatible elevation of the FloatingActionButton.

Related XML Attributes:

Parameters
elevation float: The backward compatible elevation in pixels.

See also:

setImageResource

void setImageResource (int resId)

Parameters
resId int

setRippleColor

added in version 24.1.0
void setRippleColor (int color)

Sets the ripple color for this button.

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

Related XML Attributes:

Parameters
color int: ARGB color to use for the ripple

See also:

setSize

added in version 24.1.0
void setSize (int size)

Sets the size of the button.

The options relate to the options available on the material design specification. SIZE_NORMAL is larger than SIZE_MINI. SIZE_AUTO will choose an appropriate size based on the screen size.

Related XML Attributes:

Parameters
size int: one of SIZE_NORMAL, SIZE_MINI or SIZE_AUTO

setUseCompatPadding

added in version 24.1.0
void setUseCompatPadding (boolean useCompatPadding)

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

Related XML Attributes:

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

See also:

setVisibility

void setVisibility (int visibility)

Parameters
visibility int

show

added in version 24.1.0
void show (FloatingActionButton.OnVisibilityChangedListener listener)

Shows the button.

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

Parameters
listener FloatingActionButton.OnVisibilityChangedListener: the listener to notify when this view is shown

show

added in version 24.1.0
void show ()

Shows the button.

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

Protected methods

drawableStateChanged

void drawableStateChanged ()

onAttachedToWindow

void onAttachedToWindow ()

onDetachedFromWindow

void onDetachedFromWindow ()

onMeasure

void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)