Search code examples
androidsdkandroid-snackbar

After updating targetSDK to 28 ,Snackbar is giving error?


After updating my targetSDK version to 28, I am not able to use the SnackBar

Must be one of BaseTransientBottomBar.LENGTH_INDEFINITE, BaseTransientBottomBar.LENGTH_SHORT, BaseTransientBottomBar.LENGTH_LONG or value must be ≥ 1 (was -2) less... Inspection info: Ensures that when parameter in a method only allows a specific set of constants, calls obey those rules.

My Sample Code

Here is what I have done -

Snackbar snackbar = Snackbar.make(Objects.requireNonNull(parentLayout), "Kindly allow all the permissions for  App  for a better  experience...", Snackbar.LENGTH_LONG);
 snackbar.setDuration(Snackbar.LENGTH_INDEFINITE);
 snackbar.show();

Solution

  • Read setDuration

    snackbar.setDuration(int duration);

    Set how long to show the view for. You should try with

    snackbar.setDuration(10000);