Skip to content

Commit 8729d8a

Browse files
drchenveganafro
authored andcommitted
[SnackBar] Fix maxWidth and maxInlineActionWidth are not applied
We load maxWidth and maxInlineActionWidth style attributes in SnackbarContentLayout, but the snackbar styles are only applied to SnackbarLayout. We need to pass the values to SnackbarContentLayout, as we did for actionTextColorAlpha. Resolves #781 PiperOrigin-RevId: 404320339
1 parent 01c1fc7 commit 8729d8a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ protected BaseTransientBottomBar(
375375
if (content instanceof SnackbarContentLayout) {
376376
((SnackbarContentLayout) content)
377377
.updateActionTextColorAlphaIfNeeded(view.getActionTextColorAlpha());
378+
((SnackbarContentLayout) content).setMaxInlineActionWidth(view.getMaxInlineActionWidth());
379+
((SnackbarContentLayout) content).setMaxWidth(view.getMaxWidth());
378380
}
379381
view.addView(content);
380382

@@ -1131,6 +1133,8 @@ public boolean onTouch(View v, MotionEvent event) {
11311133
@AnimationMode private int animationMode;
11321134
private final float backgroundOverlayColorAlpha;
11331135
private final float actionTextColorAlpha;
1136+
private final int maxWidth;
1137+
private final int maxInlineActionWidth;
11341138
private ColorStateList backgroundTint;
11351139
private PorterDuff.Mode backgroundTintMode;
11361140

@@ -1158,6 +1162,9 @@ protected SnackbarBaseLayout(@NonNull Context context, AttributeSet attrs) {
11581162
ViewUtils.parseTintMode(
11591163
a.getInt(R.styleable.SnackbarLayout_backgroundTintMode, -1), PorterDuff.Mode.SRC_IN));
11601164
actionTextColorAlpha = a.getFloat(R.styleable.SnackbarLayout_actionTextColorAlpha, 1);
1165+
maxWidth = a.getDimensionPixelSize(R.styleable.SnackbarLayout_android_maxWidth, -1);
1166+
maxInlineActionWidth =
1167+
a.getDimensionPixelSize(R.styleable.SnackbarLayout_maxActionInlineWidth, -1);
11611168
a.recycle();
11621169

11631170
setOnTouchListener(consumeAllTouchListener);
@@ -1268,6 +1275,14 @@ float getActionTextColorAlpha() {
12681275
return actionTextColorAlpha;
12691276
}
12701277

1278+
int getMaxWidth() {
1279+
return maxWidth;
1280+
}
1281+
1282+
int getMaxInlineActionWidth() {
1283+
return maxInlineActionWidth;
1284+
}
1285+
12711286
@NonNull
12721287
private Drawable createThemedBackground() {
12731288
float cornerRadius =

lib/java/com/google/android/material/snackbar/SnackbarContentLayout.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
2121

2222
import android.content.Context;
23-
import android.content.res.TypedArray;
2423
import androidx.core.view.ViewCompat;
2524
import android.util.AttributeSet;
2625
import android.view.View;
@@ -47,11 +46,6 @@ public SnackbarContentLayout(@NonNull Context context) {
4746

4847
public SnackbarContentLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
4948
super(context, attrs);
50-
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SnackbarLayout);
51-
maxWidth = a.getDimensionPixelSize(R.styleable.SnackbarLayout_android_maxWidth, -1);
52-
maxInlineActionWidth =
53-
a.getDimensionPixelSize(R.styleable.SnackbarLayout_maxActionInlineWidth, -1);
54-
a.recycle();
5549
}
5650

5751
@Override
@@ -168,4 +162,8 @@ public void animateContentOut(int delay, int duration) {
168162
public void setMaxInlineActionWidth(int width) {
169163
maxInlineActionWidth = width;
170164
}
165+
166+
void setMaxWidth(int width) {
167+
maxWidth = width;
168+
}
171169
}

0 commit comments

Comments
 (0)