Since I've migrated my Android Project to AndroidX i am receiving the following lint error:
Error: Must be one of: Snackbar.LENGTH_INDEFINITE, Snackbar.LENGTH_SHORT, Snackbar.LENGTH_LONG [WrongConstant]
Snackbar snackbar = Snackbar.make(rootView, message, sticky ? Snackbar.LENGTH_INDEFINITE : 4500
So instead of defining a custom duration (4500ms), I am now using Snackbar.LENGTH_LONG
.
Since i am implementing some time-based operation that depends on how long the snackbar is visible, I need to know the actual duration of Snackbar.LENGTH_LONG
in milliseconds. How do I find out that value?
The docs are not really helpful here:
Show the Snackbar for a short period of time.
The duration should be LENGTH_SHORT, LENGTH_LONG or LENGTH_INDEFINITE. When LENGTH_INDEFINITE is used, the snackbar will be displayed indefinite time and can be dismissed with swipe off. And you can set the duration of your snackbar by setDuration(int) method.
Snackbar in android is a new widget introduced with the Material Design library as a replacement of a Toast. Android Snackbar is light-weight widget and they are used to show messages in the bottom of the application with swiping enabled. Snackbar android widget may contain an optional action button.
Snackbars provide lightweight feedback about an operation. They show a brief message at the bottom of the screen on mobile and lower left on larger devices. Snackbars appear above all other elements on screen and only one can be displayed at a time.
You can use a Snackbar to display a brief message to the user. Unlike Notifications, the message automatically goes away after a short period. A Snackbar is ideal for brief messages that the user doesn't necessarily need to act on.
After some fishing in the source code you will find these constants in the SnackbarManager
:
private static final int SHORT_DURATION_MS = 1500;
private static final int LONG_DURATION_MS = 2750;
So to answer your question the actual duration for the long length is 2750 milliseconds.
Class com.google.android.material.snackbar.SnackbarManager
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With