私はcom.android.support:appcompat-v7:26.1.0を使用しており、正常にSnackbar.LENGTH_INDEFINITE
動作します。サンプルは次のようになります。
private HashMap<Long, Snackbar> mTokenSnackbarMap = new LinkedHashMap<>();
private void dropPoint(@NonNull Location location) {
final Long token = SystemClock.elapsedRealtime();
// <submitPoint> is the callback to be executed
// at a time in the future, if the "cancel" button
// of the Snackbar isn't clicked until that time.
Runnable submitPoint = () -> {
Snackbar bar = mTokenSnackbarMap.get(token);
if (bar != null) {
// "cancel" button of the Snackbar wasn't clicked,
// but our time is up. Dismiss the Snackbar.
bar.dismiss();
mTokenSnackbarMap.remove(token);
Log.i(TAG, "dropPoint: dismiss snackbar");
}
mDatabase.add(Point.Factory.create(uid, location));
Log.i(TAG, "dropPoint: addPoint");
};
// The indefinite Snackbar allowing arbitrary cancellation.
Snackbar snackbar = Snackbar.make(mMainView, R.string.point_pending, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.cancel, (v) -> {
mTokenSnackbarMap.remove(token);
mUiHandler.removeCallbacks(submitPoint, token);
Log.i(TAG, "dropPoint: cancel snackbar");
});
mTokenSnackbarMap.put(token, snackbar);
mUiHandler.postAtTime(submitPoint, token,
SystemClock.uptimeMillis() + Constants.POINT_DELAY_MILLIS);
Log.i(TAG, "dropPoint: postAtTime");
snackbar.show();
}