-
- All Implemented Interfaces:
-
android.graphics.drawable.Drawable.Callback
,android.view.KeyEvent.Callback
,android.view.accessibility.AccessibilityEventSource
,androidx.coordinatorlayout.widget.CoordinatorLayout.AttachedBehavior
,androidx.core.view.TintableBackgroundView
,androidx.core.widget.TintableImageSourceView
,com.google.android.material.expandable.ExpandableTransformationWidget
,com.google.android.material.expandable.ExpandableWidget
,com.google.android.material.shape.Shapeable
public final class ExpandableFab extends FloatingActionButton
The design and behavior of a Floating Action Button which can animate and expand to show optional FabOptions when clicked. It's the focal point for the ExpandableFab widget's functionality, from an end-user's perspective.
Developer Notes:
Layout_width and layout_height should be set to wrap_content, unless you're setting custom dimensions.
ExpandableFabs must be defined within an ExpandableFabLayout to function properly.
label.labelText must be non-null for the optional label to show and other label properties to take effect.
Implementation Notes:
Since the Kotlin 'internal' modifier translates to 'public' in Java, the JvmSynthetic annotation is used on those functions and properties to hide them from the published API for Java clients. A proper solution to this issue would be a package-private visibility modifier, but Kotlin has yet to implement it (https://youtrack.jetbrains.com/issue/KT-29227). Until then, the JvmSynthetic annotations should remain in order to present the proper published API to both Java & Kotlin clients.
-
-
Field Summary
Fields Modifier and Type Field Description private Orientation
orientation
private Integer
efabColor
private Drawable
efabIcon
private FabSize
efabSize
private Boolean
efabEnabled
private Float
iconAnimationRotationDeg
private FabSize
fabOptionSize
private FabOptionPosition
fabOptionPosition
private Float
firstFabOptionMarginPx
private Float
successiveFabOptionMarginPx
private Long
openingAnimationDurationMs
private Long
closingAnimationDurationMs
private Float
closingAnticipateTension
private final Label
label
-
Constructor Summary
Constructors Constructor Description ExpandableFab(Context context, Orientation orientation)
Used to create an ExpandableFab programmatically (do not use the other constructor ExpandableFab(context, attributeSet) - it is for use by the Android framework when inflating an ExpandableFab via XML). ExpandableFab(Context context, AttributeSet attributeSet)
Called by the system when creating an ExpandableFab via XML (don't call this directly).
-
Method Summary
Modifier and Type Method Description final Orientation
getOrientation()
The Orientation this ExpandableFab is viewable in. final Unit
setOrientation(Orientation orientation)
final Integer
getEfabColor()
The color of the ExpandableFab, as an integer in the form 0xAARRGGBB. final Unit
setEfabColor(Integer efabColor)
final Drawable
getEfabIcon()
The drawable to show as the ExpandableFab's icon. final Unit
setEfabIcon(Drawable efabIcon)
final FabSize
getEfabSize()
The size of this ExpandableFab (NOT its FabOptions. final Unit
setEfabSize(FabSize efabSize)
final Boolean
getEfabEnabled()
The enabled state of this ExpandableFab and its label. final Unit
setEfabEnabled(Boolean efabEnabled)
final Float
getIconAnimationRotationDeg()
A float, in degrees, representing how much the ExpandableFab's icon will rotate when animating. final Unit
setIconAnimationRotationDeg(Float iconAnimationRotationDeg)
A float, in degrees, representing how much the ExpandableFab's icon will rotate when animating. final FabSize
getFabOptionSize()
The size of each FabOption in this orientation (NOT the size of the ExpandableFab. final Unit
setFabOptionSize(FabSize fabOptionSize)
The size of each FabOption in this orientation (NOT the size of the ExpandableFab. final FabOptionPosition
getFabOptionPosition()
How each FabOption in this orientation will be positioned relative to the previous FabOption. final Unit
setFabOptionPosition(FabOptionPosition fabOptionPosition)
How each FabOption in this orientation will be positioned relative to the previous FabOption. final Float
getFirstFabOptionMarginPx()
The margin (in pixels as a positive float) between the first FabOption in this orientation and the ExpandableFab itself. final Unit
setFirstFabOptionMarginPx(Float firstFabOptionMarginPx)
final Float
getSuccessiveFabOptionMarginPx()
The margin (in pixels as a positive float) between successive FabOptions in this ExpandableFab orientation. final Unit
setSuccessiveFabOptionMarginPx(Float successiveFabOptionMarginPx)
final Long
getOpeningAnimationDurationMs()
The duration (in milliseconds as a positive long) of the ExpandableFab's opening animations. final Unit
setOpeningAnimationDurationMs(Long openingAnimationDurationMs)
final Long
getClosingAnimationDurationMs()
The duration (in milliseconds as a positive long) of the ExpandableFab's closing animations. final Unit
setClosingAnimationDurationMs(Long closingAnimationDurationMs)
final Float
getClosingAnticipateTension()
The tension (as a positive float) applied on the ExpandableFab's icon to mimic an AnticipateInterpolator when it's playing its closing animations. final Unit
setClosingAnticipateTension(Float closingAnticipateTension)
final Label
getLabel()
The optional label attached to this ExpandableFab. Unit
setOnClickListener(View.OnClickListener onClickListener)
Registers a callback to be invoked when this ExpandableFab or its label is clicked. Unit
show()
Shows the ExpandableFab and optional label. Unit
hide()
Hides the ExpandableFab and optional label. Unit
setSize(Integer size)
Sets the size of the ExpandableFab. -
-
Constructor Detail
-
ExpandableFab
ExpandableFab(Context context, Orientation orientation)
Used to create an ExpandableFab programmatically (do not use the other constructor ExpandableFab(context, attributeSet) - it is for use by the Android framework when inflating an ExpandableFab via XML).
-
ExpandableFab
ExpandableFab(Context context, AttributeSet attributeSet)
Called by the system when creating an ExpandableFab via XML (don't call this directly).
-
-
Method Detail
-
getOrientation
final Orientation getOrientation()
The Orientation this ExpandableFab is viewable in. Default value is Orientation.PORTRAIT.
-
setOrientation
final Unit setOrientation(Orientation orientation)
-
getEfabColor
final Integer getEfabColor()
The color of the ExpandableFab, as an integer in the form 0xAARRGGBB.
If using an XML resource color value, retrieve it in the correct form by calling: ContextCompat.getColor(context, R.color.name_of_color_resource).
Default value is the colorAccent value defined in your app theme (styles.xml). If colorAccent is not defined in your app theme, colorSecondary may be used.
Usage of this property is preferred over the inherited setBackgroundColor and backgroundTintList methods.
-
setEfabColor
final Unit setEfabColor(Integer efabColor)
-
getEfabIcon
final Drawable getEfabIcon()
The drawable to show as the ExpandableFab's icon. Default value is a white plus sign vector drawable.
Usage of this property is preferred over the inherited set/getImageXXX methods.
-
setEfabIcon
final Unit setEfabIcon(Drawable efabIcon)
-
getEfabSize
final FabSize getEfabSize()
The size of this ExpandableFab (NOT its FabOptions. For that, see property fabOptionSize). Must be FabSize.MINI, FabSize.NORMAL, FabSize.AUTO or FabSize.CUSTOM. FabSize.CUSTOM should be used when you're setting the size of the ExpandableFab's layout_width and layout_height to a custom value manually (when using CUSTOM, make sure to also set app:fabCustomSize equal to your custom layout_width/layout_height size and app:maxImageSize equal to your icon size in order to ensure your icon is centered properly). Default value is FabSize.NORMAL.
Usage of this property is preferred over the inherited set/getSize methods.
-
setEfabSize
final Unit setEfabSize(FabSize efabSize)
-
getEfabEnabled
final Boolean getEfabEnabled()
The enabled state of this ExpandableFab and its label. Disabled ExpandableFabs and labels will be visually distinct and unclickable. Default value is true (enabled).
Usage of this property is preferred over the inherited is/setEnabled methods.
NOTE: If you disable an ExpandableFab and its label, remember to re-enable it before trying to update one of its properties. For example, disabling an ExpandableFab then manually changing its background color will not automatically re-enable the ExpandableFab. It, and its label, will remain disabled.
-
setEfabEnabled
final Unit setEfabEnabled(Boolean efabEnabled)
-
getIconAnimationRotationDeg
final Float getIconAnimationRotationDeg()
A float, in degrees, representing how much the ExpandableFab's icon will rotate when animating. When opening, the ExpandableFab will rotate from 0 to this value. When closing, the icon will rotate from this value to its initial position of 0. Default value is -135f.
-
setIconAnimationRotationDeg
final Unit setIconAnimationRotationDeg(Float iconAnimationRotationDeg)
A float, in degrees, representing how much the ExpandableFab's icon will rotate when animating. When opening, the ExpandableFab will rotate from 0 to this value. When closing, the icon will rotate from this value to its initial position of 0. Default value is -135f.
-
getFabOptionSize
final FabSize getFabOptionSize()
The size of each FabOption in this orientation (NOT the size of the ExpandableFab. For that, see property efabSize). Must be FabSize.MINI, FabSize.NORMAL, FabSize.AUTO or FabSize.CUSTOM. FabSize.CUSTOM should be used when you're setting the size of the FabOptions' layout_width and layout_height to a custom value manually (when using CUSTOM, make sure to also set app:fabCustomSize equal to your custom layout_width/layout_height size and app:maxImageSize equal to your icon size in order to ensure your icon is centered properly). Default value is FabSize.MINI.
Usage of this property is preferred over the inherited set/getSize methods on individual FabOptions.
-
setFabOptionSize
final Unit setFabOptionSize(FabSize fabOptionSize)
The size of each FabOption in this orientation (NOT the size of the ExpandableFab. For that, see property efabSize). Must be FabSize.MINI, FabSize.NORMAL, FabSize.AUTO or FabSize.CUSTOM. FabSize.CUSTOM should be used when you're setting the size of the FabOptions' layout_width and layout_height to a custom value manually (when using CUSTOM, make sure to also set app:fabCustomSize equal to your custom layout_width/layout_height size and app:maxImageSize equal to your icon size in order to ensure your icon is centered properly). Default value is FabSize.MINI.
Usage of this property is preferred over the inherited set/getSize methods on individual FabOptions.
-
getFabOptionPosition
final FabOptionPosition getFabOptionPosition()
How each FabOption in this orientation will be positioned relative to the previous FabOption. Default value is FabOptionPosition.ABOVE.
-
setFabOptionPosition
final Unit setFabOptionPosition(FabOptionPosition fabOptionPosition)
How each FabOption in this orientation will be positioned relative to the previous FabOption. Default value is FabOptionPosition.ABOVE.
-
getFirstFabOptionMarginPx
final Float getFirstFabOptionMarginPx()
The margin (in pixels as a positive float) between the first FabOption in this orientation and the ExpandableFab itself. Depending on the size you set for the ExpandableFab, you may want this margin to be different than successiveFabOptionMarginPx. Default value is 80f.
-
setFirstFabOptionMarginPx
final Unit setFirstFabOptionMarginPx(Float firstFabOptionMarginPx)
-
getSuccessiveFabOptionMarginPx
final Float getSuccessiveFabOptionMarginPx()
The margin (in pixels as a positive float) between successive FabOptions in this ExpandableFab orientation. See firstFabOptionMarginPx if trying to set the margin between the first FabOption in this orientation and the ExpandableFab itself. Default value is 75f.
-
setSuccessiveFabOptionMarginPx
final Unit setSuccessiveFabOptionMarginPx(Float successiveFabOptionMarginPx)
-
getOpeningAnimationDurationMs
final Long getOpeningAnimationDurationMs()
The duration (in milliseconds as a positive long) of the ExpandableFab's opening animations. Set to 0L if you don't want opening animations played. Default value is 250L.
-
setOpeningAnimationDurationMs
final Unit setOpeningAnimationDurationMs(Long openingAnimationDurationMs)
-
getClosingAnimationDurationMs
final Long getClosingAnimationDurationMs()
The duration (in milliseconds as a positive long) of the ExpandableFab's closing animations. Set to 0L if you don't want closing animations played. Default value is 500L.
-
setClosingAnimationDurationMs
final Unit setClosingAnimationDurationMs(Long closingAnimationDurationMs)
-
getClosingAnticipateTension
final Float getClosingAnticipateTension()
The tension (as a positive float) applied on the ExpandableFab's icon to mimic an AnticipateInterpolator when it's playing its closing animations. An AnticipateInterpolator allows us to have a closing animation where the ExpandableFab's icon will begin rotating slightly backwards, before smoothly rotating forward to its default 0 degree rotation. Every multiple of 10f will be a full 360 degree rotation backwards. Default value is 2f.
-
setClosingAnticipateTension
final Unit setClosingAnticipateTension(Float closingAnticipateTension)
-
getLabel
final Label getLabel()
The optional label attached to this ExpandableFab. The label will only be shown when its labelText is not null. Default values for the label are as follows:
labelText = null labelTextColor = white labelTextSize = 14sp labelFont = Typeface.DEFAULT labelBackgroundColor = gray (#333333) labelElevation = 6dp position = LabelPosition.LEFT marginPx = 50f translationPx = 100f visibleToHiddenAnimationDurationMs = 125L hiddenToVisibleAnimationDurationMs = 250L overshootTension = 3.5f
-
setOnClickListener
Unit setOnClickListener(View.OnClickListener onClickListener)
Registers a callback to be invoked when this ExpandableFab or its label is clicked. The default behavior the ExpandableFab will be executed before this custom callback.
-
setSize
Unit setSize(Integer size)
Sets the size of the ExpandableFab. Overridden to ensure we never set the size to be FabSize.CUSTOM.
Clients should never need to call this directly. Instead, set ExpandableFab.efabSize.
-
-
-
-