How to use setDuration() method in SnackBar (Android Design Support Library) -
from documentation: parameter duration - either 1 of predefined lengths: length_short, length_long, or custom duration in milliseconds. can't set custom duration.
for example
snackbar .make(parentlayout, "feed cat?", 8000) // try here .setaction("yes", snackonclicklistener) .setactiontextcolor(color.magenta) .setduration(8000) // try here .show(); but instead of 8 seconds snackbar gone quickly.
based on implementation of snackbar , snackbarmanager, can confirm eugene h's assessment: it's bug. snackbarmanager:
private void scheduletimeoutlocked(snackbarrecord r) { mhandler.removecallbacksandmessages(r); mhandler.sendmessagedelayed(message.obtain(mhandler, msg_timeout, r), r.duration == snackbar.length_long ? long_duration_ms : short_duration_ms); } so, value not length_long results in short-duration snackbar.
i have filed an issue it.
edit: has been fixed in revision 22.2.1. check release notes here
the android docs have not been updated yet, if jump source code you'll notice parameter method setduration(int duration) can either 1 of length_short, length_long, length_indefinite or custom duration in milliseconds
Comments
Post a Comment