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.

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.

Constructors

Link copied to clipboard
constructor(@NonNull context: Context)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet, defStyleAttr: Int)

Types

Link copied to clipboard
open class Behavior : FloatingActionButton.BaseBehavior<T>
Behavior designed for use with FloatingActionButton instances.
Link copied to clipboard
Callback to be invoked when the visibility of a FloatingActionButton changes.
Link copied to clipboard
annotation class Size

Properties

Link copied to clipboard
Link copied to clipboard
@get:Px
open var customSize: Int
Link copied to clipboard
Indicates that the FloatingActionButton should not have a custom size, and instead that the size should be calculated based on the value set using setSize or the fabSize attribute.
Link copied to clipboard
open var size: Int
Link copied to clipboard
val SIZE_AUTO: Int = -1
Size which will change based on the window size.
Link copied to clipboard
val SIZE_MINI: Int = 1
The mini sized button, 40dp.
Link copied to clipboard
val SIZE_NORMAL: Int = 0
The normal sized button, 56dp.

Functions

Link copied to clipboard
Add a TransformationCallback which can watch for changes to this view.
Link copied to clipboard
open fun clearCustomSize()
Clears the custom size for this FloatingActionButton.
Link copied to clipboard
Returns the tint applied to the background drawable, if specified.
Link copied to clipboard
Returns the backward compatible elevation of the FloatingActionButton.
Link copied to clipboard
Returns the backward compatible hovered/focused translationZ of the FloatingActionButton.
Link copied to clipboard
Returns the backward compatible pressed translationZ of the FloatingActionButton.
Link copied to clipboard
Returns the FloatingActionButton's background, minus any compatible shadow implementation.
Link copied to clipboard
open fun getContentRect(@NonNull rect: Rect): Boolean
Return in rect the bounds of the actual floating action button content in view-local coordinates.
Link copied to clipboard
Returns the expanded component id hint.
Link copied to clipboard
Returns the motion spec for the hide animation.
Link copied to clipboard
Return in rect the bounds of the actual floating action button content in view-local coordinates.
Link copied to clipboard
Returns the ripple color for this button.
Link copied to clipboard
Returns the ripple color for this button.
Link copied to clipboard
Returns the motion spec for the show animation.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Returns whether FloatingActionButton will add inner padding on platforms Lollipop and after.
Link copied to clipboard
open fun hide()
Hides the button.
Link copied to clipboard
open fun isExpanded(): Boolean
Returns whether this widget is expanded.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun setBackgroundColor(color: Int)
Link copied to clipboard
open fun setBackgroundDrawable(background: Drawable)
Link copied to clipboard
open fun setBackgroundResource(resid: Int)
Link copied to clipboard
Applies a tint to the background drawable.
Link copied to clipboard
open fun setCompatElevation(elevation: Float)
Updates the backward compatible elevation of the FloatingActionButton.
Link copied to clipboard
Updates the backward compatible elevation of the FloatingActionButton.
Link copied to clipboard
Updates the backward compatible hovered/focused translationZ of the FloatingActionButton.
Updates the backward compatible hovered/focused translationZ of the FloatingActionButton.
Link copied to clipboard
open fun setCompatPressedTranslationZ(translationZ: Float)
Updates the backward compatible pressed translationZ of the FloatingActionButton.
Link copied to clipboard
Updates the backward compatible pressed translationZ of the FloatingActionButton.
Link copied to clipboard
Link copied to clipboard
Sets whether this FloatingActionButton should expand its bounds (if needed) to meet the minimum touch target size.
Link copied to clipboard
open fun setExpanded(expanded: Boolean): Boolean
Sets the expanded state on this widget.
Link copied to clipboard
open fun setExpandedComponentIdHint(@IdRes expandedComponentIdHint: Int)
Sets the expanded component id hint, which may be used by a Behavior to determine whether it should handle this widget's state change.
Link copied to clipboard
Updates the motion spec for the hide animation.
Link copied to clipboard
Updates the motion spec for the hide animation.
Link copied to clipboard
open fun setImageDrawable(@Nullable drawable: Drawable)
Link copied to clipboard
open fun setImageResource(@DrawableRes resId: Int)
Link copied to clipboard
open fun setMaxImageSize(imageSize: Int)
Sets the max image size for this button.
Link copied to clipboard
open fun setRippleColor(@ColorInt color: Int)
Sets the ripple color for this button.
Link copied to clipboard
open fun setScaleX(scaleX: Float)
Link copied to clipboard
open fun setScaleY(scaleY: Float)
Link copied to clipboard
Set whether padding to show compat shadows should be added.
Link copied to clipboard
Link copied to clipboard
Updates the motion spec for the show animation.
Link copied to clipboard
Updates the motion spec for the show animation.
Link copied to clipboard
Link copied to clipboard
Compat method to support TintableBackgroundView.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun setTranslationX(translationX: Float)
Link copied to clipboard
open fun setTranslationY(translationY: Float)
Link copied to clipboard
open fun setTranslationZ(translationZ: Float)
Link copied to clipboard
open fun setUseCompatPadding(useCompatPadding: Boolean)
Set whether FloatingActionButton should add inner padding on platforms Lollipop and after, to ensure consistent dimensions on all platforms.
Link copied to clipboard
open fun setVisibility(visibility: Int)
Link copied to clipboard
Returns whether this fab will expand its bounds (if needed) to meet the minimum touch target size.
Link copied to clipboard
open fun show()
Shows the button.