Snackbar (de 'com.android.support:design:23.2.1' ) suporta muitos tipos de ação de dispensar. Você pode criar um filtro simples usando evento , como neste exemplo:
Snackbar.make(view, wornMessage, Snackbar.LENGTH_LONG).setActionTextColor(context.getResources().getColor(R.color.primary))
.setCallback(new Snackbar.Callback() {
@Override
public void onShown(Snackbar snackbar) {
super.onShown(snackbar);
// when snackbar is showing
}
@Override
public void onDismissed(Snackbar snackbar, int event) {
super.onDismissed(snackbar, event);
if (event != DISMISS_EVENT_ACTION) {
//will be true if user not click on Action button (for example: manual dismiss, dismiss by swipe
}
}
})
.setAction("Undo, view1 -> {
// if user click on Action button
}).show();
Tipos de dispensa do Snackbar:
/** Indicates that the Snackbar was dismissed via a swipe.*/
public static final int DISMISS_EVENT_SWIPE = 0;
/** Indicates that the Snackbar was dismissed via an action click.*/
public static final int DISMISS_EVENT_ACTION = 1;
/** Indicates that the Snackbar was dismissed via a timeout.*/
public static final int DISMISS_EVENT_TIMEOUT = 2;
/** Indicates that the Snackbar was dismissed via a call to {@link #dismiss()}.*/
public static final int DISMISS_EVENT_MANUAL = 3;
/** Indicates that the Snackbar was dismissed from a new Snackbar being shown.*/
public static final int DISMISS_EVENT_CONSECUTIVE = 4;
PS No código de amostra usado expressões lambda (por RetroLambda)
Snackbar
é contra as Diretrizes de design de materiais do Google .