带有 Callback 的 Android Snackbar
示例
您可以使用它Snackbar.Callback来听小吃板是否被用户关闭或超时。
Snackbar.make(getView(), "嗨,小吃吧!", 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(getActivity(), "Clicked the action", Toast.LENGTH_LONG).show(); break; case Snackbar.Callback.DISMISS_EVENT_TIMEOUT: Toast.makeText(getActivity(), "Time out", Toast.LENGTH_LONG).show(); break; } } @Override public void onShown(Snackbar snackbar) { Toast.makeText(getActivity(), "This is my annoying step-brother", Toast.LENGTH_LONG).show(); } }).setAction("Go!", new View.OnClickListener() { @Override public void onClick(View v) { } }).show();