Snackbar (de 'com.android.support:design:23.2.1' ) admite muchos tipos de acciones de descarte. Puede crear un filtro simple usando evento , como en este ejemplo:
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 descarte de 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 En el código de muestra se utilizaron expresiones lambda (por RetroLambda)
Snackbar
está en contra de las Directrices de diseño de materiales de Google .