Skip to content

Toast vs Snackbar: Practical considerations

Li-Wei Yap edited this page Jan 26, 2022 · 12 revisions

Toast vs Snackbar: Practical considerations

  • From API level 31 onwards, both Toast and Snackbar are limited to only 2 lines by default, but it seems that we can style our own Snackbar using ?attr/snackbarStyle, ?attr/snackbarButtonStyle, and ?attr/snackbarTextViewStyle. (See the section on styles in the docs.)
  • Toast takes in a Context parameter (which should be an Application Context rather than an Activity Context), whereas Snackbar does not, as it takes in only a View parameter. This makes Context memory leaks impossible from a Snackbar. Also, see this Twitter thread by none other than the creator of LeakCanary.
  • Snackbar offers more flexibility than Toast:
    • We can adjust the vertical position (in both the XY-plane and in the Z-axis) of a Snackbar.
    • Snackbar can be dismissed early by a swipe.
    • It seems that if we tap and hold on a Snackbar, then we will delay its dismissal? 👍