@@ -110,6 +110,13 @@ public void onDismissed(Snackbar transientBottomBar, @DismissEvent int event) {
110110
111111 @ Nullable private BaseCallback <Snackbar > callback ;
112112
113+ /**
114+ * This is only used as a temporary flag to opt-out of the new dismissal behavior for Snackbar
115+ * with actions, which will never time out.
116+ */
117+ @ SuppressWarnings ("unused" )
118+ private boolean useLegacyDismissalBehavior = false ;
119+
113120 private Snackbar (
114121 @ NonNull Context context ,
115122 @ NonNull ViewGroup parent ,
@@ -164,6 +171,27 @@ public static Snackbar make(
164171 return makeInternal (/* context= */ null , view , text , duration );
165172 }
166173
174+ /**
175+ * Make a Snackbar to display a message.
176+ *
177+ * <p>Snackbar will try and find a parent view to hold Snackbar's view from the value given to
178+ * {@code view}. Snackbar will walk up the view tree trying to find a suitable parent, which is
179+ * defined as a {@link CoordinatorLayout} or the window decor's content view, whichever comes
180+ * first.
181+ *
182+ * <p>Having a {@link CoordinatorLayout} in your view hierarchy allows Snackbar to enable certain
183+ * features, such as swipe-to-dismiss and automatically moving of widgets.
184+ *
185+ * @param view The view to find a parent from.
186+ * @param resId The resource id of the string resource to use. Can be formatted text.
187+ * @param duration How long to display the message. Can be {@link #LENGTH_SHORT}, {@link
188+ * #LENGTH_LONG}, {@link #LENGTH_INDEFINITE}, or a custom duration in milliseconds.
189+ */
190+ @ NonNull
191+ public static Snackbar make (@ NonNull View view , @ StringRes int resId , @ Duration int duration ) {
192+ return make (view , view .getResources ().getText (resId ), duration );
193+ }
194+
167195 /**
168196 * Make a Snackbar to display a message
169197 *
@@ -248,27 +276,6 @@ private static boolean hasSnackbarContentStyleAttrs(@NonNull Context context) {
248276 return snackbarButtonStyleResId != -1 && snackbarTextViewStyleResId != -1 ;
249277 }
250278
251- /**
252- * Make a Snackbar to display a message.
253- *
254- * <p>Snackbar will try and find a parent view to hold Snackbar's view from the value given to
255- * {@code view}. Snackbar will walk up the view tree trying to find a suitable parent, which is
256- * defined as a {@link CoordinatorLayout} or the window decor's content view, whichever comes
257- * first.
258- *
259- * <p>Having a {@link CoordinatorLayout} in your view hierarchy allows Snackbar to enable certain
260- * features, such as swipe-to-dismiss and automatically moving of widgets.
261- *
262- * @param view The view to find a parent from.
263- * @param resId The resource id of the string resource to use. Can be formatted text.
264- * @param duration How long to display the message. Can be {@link #LENGTH_SHORT}, {@link
265- * #LENGTH_LONG}, {@link #LENGTH_INDEFINITE}, or a custom duration in milliseconds.
266- */
267- @ NonNull
268- public static Snackbar make (@ NonNull View view , @ StringRes int resId , @ Duration int duration ) {
269- return make (view , view .getResources ().getText (resId ), duration );
270- }
271-
272279 @ Nullable
273280 private static ViewGroup findSuitableParent (View view ) {
274281 ViewGroup fallback = null ;
@@ -362,6 +369,18 @@ public Snackbar setAction(
362369 return this ;
363370 }
364371
372+ /**
373+ * Set whether to use the legacy dismissal behavior for Snackbar with actions. This is a temporary
374+ * flag to allow apps to migrate to the new behavior, which will never timeout the Snackbar with
375+ * actions. Do not use this for new usages.
376+ */
377+ @ NonNull
378+ @ CanIgnoreReturnValue
379+ public Snackbar setUseLegacyDismissalBehavior (boolean useLegacyDismissalBehavior ) {
380+ this .useLegacyDismissalBehavior = useLegacyDismissalBehavior ;
381+ return this ;
382+ }
383+
365384 @ Override
366385 @ Duration
367386 public int getDuration () {
0 commit comments