这是解决您问题的部分片段,尽管它可能不是正确的处理方式:
//using a queue to pass string to the snackbar
Queue<String> myQueue = new LinkedList<String>();
myQueue.offer("item 1");
myQueue.offer("item 2");
myQueue.offer("item 3");
displaysnack(myQueue, view);
public void displaysnack(final Queue dQueue, final View view){
Snackbar.make(view, (String)dQueue.poll(), Snackbar.LENGTH_LONG).setCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar snackbar, int event) {
switch (event) {
case Snackbar.Callback.DISMISS_EVENT_ACTION:
Toast.makeText(getApplicationContext(), "Clicked the action", Toast.LENGTH_LONG).show();
break;
//once the timeout expires, display the next one in the queue.
case Snackbar.Callback.DISMISS_EVENT_TIMEOUT:
Toast.makeText(getApplicationContext(), "Showing: "+ (dQueue.size()), Toast.LENGTH_SHORT).show();
if (dQueue.size()>0){displaysnack(dQueue, view);}
break;
case Snackbar.Callback.DISMISS_EVENT_CONSECUTIVE:
//Toast.makeText(getApplicationContext(), "Multiple Shown", Toast.LENGTH_SHORT).show();
break;
}
}