Daniel Rotenberg
07/25/2022, 8:59 PMKari Kähkönen
07/26/2022, 8:17 AMSnackbarHost(it) { data ->
Snackbar(
backgroundColor = Color.Black,
shape = RoundedCornerShape(12.dp),
modifier = Modifier.padding(8.dp)
) {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(<http://Icons.Outlined.Info|Icons.Outlined.Info>, contentDescription = null, modifier = Modifier.padding(end = 16.dp))
Text(data.message)
}
Icon(Icons.Default.Close, contentDescription = null, modifier = Modifier.clickable { data.dismiss() })
}
}
}
If you need to have multiple different looking snackbars in your application, then it gets more difficult. At least I haven't found out a way to pass custom data to the snackbar host. One way is to encode additional data in the snackbar message (e.g., "blue#some random message" and just display message after the "#" to the user ), but that is a bit hacky.