mirror of
https://github.com/material-components/material-components-android.git
synced 2026-01-09 07:11:07 +08:00
[FloatingActionButton] Allow collapsed size to be set.
PiperOrigin-RevId: 834422708
This commit is contained in:
parent
6b3be338a8
commit
0153138811
@ -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`
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user