Skip to content

Commit dc98ca0

Browse files
pekingmeimhappi
authored andcommitted
[Button] Fixed width morph with contents change.
PiperOrigin-RevId: 825101222
1 parent 1493590 commit dc98ca0

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

lib/java/com/google/android/material/button/MaterialButton.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ enum WidthChangeDirection {
228228
@AttrRes private static final int MATERIAL_SIZE_OVERLAY_ATTR = R.attr.materialSizeOverlay;
229229
private static final float OPTICAL_CENTER_RATIO = 0.11f;
230230

231-
private static final int UNSET = -1;
231+
private static final int UNSET = Integer.MIN_VALUE;
232232

233233
@NonNull private final MaterialButtonHelper materialButtonHelper;
234234

@@ -638,6 +638,24 @@ public void refreshDrawableState() {
638638
}
639639
}
640640

641+
@Override
642+
public void setText(CharSequence text, BufferType type) {
643+
originalWidth = UNSET;
644+
super.setText(text, type);
645+
}
646+
647+
@Override
648+
public void setTextAppearance(Context context, int resId) {
649+
originalWidth = UNSET;
650+
super.setTextAppearance(context, resId);
651+
}
652+
653+
@Override
654+
public void setTextSize(int unit, float size) {
655+
originalWidth = UNSET;
656+
super.setTextSize(unit, size);
657+
}
658+
641659
@Override
642660
public void setTextAlignment(int textAlignment) {
643661
super.setTextAlignment(textAlignment);
@@ -798,6 +816,14 @@ void setInternalBackground(Drawable background) {
798816
super.setBackgroundDrawable(background);
799817
}
800818

819+
@Override
820+
public void setCompoundDrawablePadding(@Px int padding) {
821+
if (getCompoundDrawablePadding() != padding) {
822+
originalWidth = UNSET;
823+
}
824+
super.setCompoundDrawablePadding(padding);
825+
}
826+
801827
/**
802828
* Sets the padding between the button icon and the button text, if icon is present.
803829
*
@@ -838,6 +864,7 @@ public void setIconSize(@Px int iconSize) {
838864
}
839865

840866
if (this.iconSize != iconSize) {
867+
originalWidth = UNSET;
841868
this.iconSize = iconSize;
842869
updateIcon(/* needsIconReset= */ true);
843870
}
@@ -866,6 +893,7 @@ public int getIconSize() {
866893
*/
867894
public void setIcon(@Nullable Drawable icon) {
868895
if (this.icon != icon) {
896+
originalWidth = UNSET;
869897
this.icon = icon;
870898
updateIcon(/* needsIconReset= */ true);
871899
updateIconPosition(getMeasuredWidth(), getMeasuredHeight());

0 commit comments

Comments
 (0)