belongs to Maven artifact com.android.support:design:27.1.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 |
class |
FloatingActionButton.OnVisibilityChangedListener
Callback to be invoked when the visibility of a FloatingActionButton changes. |
XML attributes | |
---|---|
FloatingActionButton_elevation |
|
FloatingActionButton_fabCustomSize |
|
FloatingActionButton_fabSize |
|
FloatingActionButton_rippleColor |
|
FloatingActionButton_useCompatPadding |
Constants | |
---|---|
int |
NO_CUSTOM_SIZE
Indicates that FloatingActionButton should not have a custom size. |
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 |
int
|
getCustomSize()
Returns the custom size for this button. |
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
|
void
|
setCompatElevation(float elevation)
Updates the backward compatible elevation of the FloatingActionButton. |
void
|
setCustomSize(int size)
Sets the size of the button to be a custom value in pixels. |
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_fabCustomSize
Related methods:
FloatingActionButton_fabSize
Related methods:
FloatingActionButton_rippleColor
Related methods:
FloatingActionButton_useCompatPadding
Related methods:
Constants
NO_CUSTOM_SIZE
int NO_CUSTOM_SIZE
Indicates that FloatingActionButton should not have a custom size.
Constant Value: 0 (0x00000000)
SIZE_AUTO
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
int SIZE_MINI
The mini sized button. Will always been smaller than SIZE_NORMAL
.
See also:
Constant Value: 1 (0x00000001)
SIZE_NORMAL
int SIZE_NORMAL
The normal sized button. Will always been larger than SIZE_MINI
.
See also:
Constant Value: 0 (0x00000000)
Public constructors
FloatingActionButton
FloatingActionButton (Context context)
Parameters | |
---|---|
context |
Context |
FloatingActionButton
FloatingActionButton (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
FloatingActionButton
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
float getCompatElevation ()
Returns the backward compatible elevation of the FloatingActionButton.
Related XML Attributes:
Returns | |
---|---|
float |
the backward compatible elevation in pixels. |
See also:
getContentBackground
Drawable getContentBackground ()
Returns the FloatingActionButton's background, minus any compatible shadow implementation.
Returns | |
---|---|
Drawable |
getContentRect
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. |
getCustomSize
int getCustomSize ()
Returns the custom size for this button.
Returns | |
---|---|
int |
size in pixels, or NO_CUSTOM_SIZE
|
getRippleColor
int getRippleColor ()
Returns the ripple color for this button.
Returns | |
---|---|
int |
the ARGB color used for the ripple |
See also:
getSize
int getSize ()
Returns the chosen size for this button.
Returns | |
---|---|
int |
one of SIZE_NORMAL , SIZE_MINI or SIZE_AUTO |
See also:
getUseCompatPadding
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
void hide ()
Hides the button.
This method will animate the button hide if the view has already been laid out.
hide
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 ()
setBackgroundColor
void setBackgroundColor (int color)
Parameters | |
---|---|
color |
int |
setBackgroundDrawable
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
void setCompatElevation (float elevation)
Updates the backward compatible elevation of the FloatingActionButton.
Related XML Attributes:
Parameters | |
---|---|
elevation |
float : The backward compatible elevation in pixels. |
setCustomSize
void setCustomSize (int size)
Sets the size of the button to be a custom value in pixels. If set to
NO_CUSTOM_SIZE
, custom size will not be used and size will be calculated according
to setSize(int)
method.
Related XML Attributes:
Parameters | |
---|---|
size |
int : preferred size in pixels, or zero |
setImageResource
void setImageResource (int resId)
Parameters | |
---|---|
resId |
int |
setRippleColor
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
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
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
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
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 |
Annotations
Interfaces
- AppBarLayout.OnOffsetChangedListener
- BaseTransientBottomBar.ContentViewCallback
- BottomNavigationView.OnNavigationItemReselectedListener
- BottomNavigationView.OnNavigationItemSelectedListener
- CoordinatorLayout.AttachedBehavior
- NavigationView.OnNavigationItemSelectedListener
- SwipeDismissBehavior.OnDismissListener
- TabLayout.OnTabSelectedListener
Classes
- AppBarLayout
- AppBarLayout.Behavior
- AppBarLayout.Behavior.DragCallback
- AppBarLayout.Behavior.SavedState
- AppBarLayout.LayoutParams
- AppBarLayout.ScrollingViewBehavior
- BaseTransientBottomBar
- BaseTransientBottomBar.BaseCallback
- BottomNavigationView
- BottomSheetBehavior
- BottomSheetBehavior.BottomSheetCallback
- BottomSheetBehavior.SavedState
- BottomSheetDialog
- BottomSheetDialogFragment
- CollapsingToolbarLayout
- CollapsingToolbarLayout.LayoutParams
- CoordinatorLayout
- CoordinatorLayout.Behavior
- CoordinatorLayout.LayoutParams
- CoordinatorLayout.SavedState
- FloatingActionButton
- FloatingActionButton.Behavior
- FloatingActionButton.OnVisibilityChangedListener
- NavigationView
- NavigationView.SavedState
- Snackbar
- Snackbar.Callback
- SwipeDismissBehavior
- TabItem
- TabLayout
- TabLayout.Tab
- TabLayout.TabLayoutOnPageChangeListener
- TabLayout.ViewPagerOnTabSelectedListener
- TextInputEditText
- TextInputLayout
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.