[FloatingActionButton] Allow collapsed size to be set.

PiperOrigin-RevId: 834422708
This commit is contained in:
Material Design Team 2025-11-19 13:31:48 -08:00 committed by drchen
parent 6b3be338a8
commit 0153138811
2 changed files with 11 additions and 6 deletions

View File

@ -131,7 +131,7 @@ Element | Attribute
**Color** | `app:backgroundTint` | `setBackgroundTintList`<br/>`getBackgroundTintList` | `?attr/colorPrimaryContainer` (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/color/res/color/m3_button_background_color_selector.xml))
**Stroke color** | `app:strokeColor` | `setStrokeColor`<br/>`getStrokeColor` | `null`
**Stroke width** | `app:strokeWidth` | `setStrokeWidth`<br/>`getStrokeWidth` | `0dp`
**Size** | `app:collapsedSize` | N/A |
**Size** | `app:collapsedSize` | `setCollapsedSize`<br/>`getCollapsedSize` |
**Extend Strategy** | `app:extendStrategy` | N/A | `wrap_content`
**Shape** | `app:shapeAppearance`<br/>`app:shapeAppearanceOverlay` | `setShapeAppearanceModel`<br/>`getShapeAppearanceModel` | `ShapeAppearanceOverlay.Material3.FloatingActionButton`<br/>
**Elevation** | `app:elevation` | `setElevation`<br/>`getElevation` | `6dp`

View File

@ -47,6 +47,7 @@ import androidx.annotation.ColorInt;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.annotation.RestrictTo;
import androidx.annotation.VisibleForTesting;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
@ -121,7 +122,7 @@ public class ExtendedFloatingActionButton extends MaterialButton implements Atta
@NonNull private final MotionStrategy extendStrategy;
private final MotionStrategy showStrategy = new ShowStrategy(changeVisibilityTracker);
private final MotionStrategy hideStrategy = new HideStrategy(changeVisibilityTracker);
private final int collapsedSize;
private int collapsedSize;
private int extendedPaddingStart;
private int extendedPaddingEnd;
@ -1035,19 +1036,23 @@ public class ExtendedFloatingActionButton extends MaterialButton implements Atta
}
};
int getCollapsedPadding() {
return (getCollapsedSize() - getIconSize()) / 2;
}
/**
* Shrink to the smaller value between paddingStart and paddingEnd, such that when shrunk the icon
* will be centered.
*/
@VisibleForTesting
int getCollapsedSize() {
@Px
public int getCollapsedSize() {
return collapsedSize < 0
? min(getPaddingStart(), getPaddingEnd()) * 2 + getIconSize()
: collapsedSize;
}
int getCollapsedPadding() {
return (getCollapsedSize() - getIconSize()) / 2;
public void setCollapsedSize(@Px int collapsedSize) {
this.collapsedSize = collapsedSize;
}
/**