@Composable fun SnackbarScreen() { val scope = rememberCoroutineScope() val snackbarHostState = remember { SnackbarHostState() } . . . FloatingActionButton( onClick = { //Important part here scope.launch { snackbarHostState.showSnackbar("Hello there") } // }, content = { Icon(imageVector = Icons.Default.Add, contentDescription = "") } ) SnackbarHost(hostState = snackbarHostState) }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter