Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the actual duration of a Snackbar with LENGTH_LONG

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.

like image 633
user2350644 Avatar asked Jun 14 '19 12:06

user2350644


People also ask

How do I set duration on snackbar?

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.

What is snackbar explain it with example?

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.

What is the use of snackbar?

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.

What is a snack bar notification?

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.


1 Answers

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:

enter image description here

like image 119
jbarat Avatar answered Sep 26 '22 13:09

jbarat