-
Notifications
You must be signed in to change notification settings - Fork 0
Toast vs Snackbar: Practical considerations
Li-Wei Yap edited this page Jan 26, 2022
·
12 revisions
- From API level 31 onwards, both
Toast
andSnackbar
are limited to only 2 lines by default, but it seems that we can style our ownSnackbar
using?attr/snackbarStyle
,?attr/snackbarButtonStyle
, and?attr/snackbarTextViewStyle
. (See the section on styles in the docs.) -
Toast
takes in aContext
parameter (which should be an ApplicationContext
rather than an ActivityContext
), whereasSnackbar
does not, as it takes in only aView
parameter. This makesContext
memory leaks impossible from aSnackbar
. Also, see this Twitter thread by none other than the creator of LeakCanary. -
Snackbar
offers more flexibility thanToast
:- 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? 👍
- We can adjust the vertical position (in both the XY-plane and in the Z-axis) of a