Search code examples
androidkotlinuser-interfaceandroid-jetpack-composeandroid-jetpack-compose-material3

Compose: How make it so that the Snackbar is not above the FloatingActionButton?


I want the snackbar to be under the button or at least overlap it

I'm trying to call snackbarHostState.showSnackbar(snackbarText) when the FloatingActionButton is clicked, but the call gets this:

enter image description here

In AndroidManifest i have this code:

<activity android:name=".YourActivity"
    android:windowSoftInputMode="adjustResize"/> 

What might have affected the location of the FloatingActionButton in Scaffold:

Scaffold(
    snackbarHost = { SnackbarHost(hostState = snackbarHostState) }
    floatingActionButtonPosition = FabPosition.End,
    floatingActionButton = {
                         FloatingActionButton(
                             onClick = { snackbarHostState.showSnackbar(snackbarText) },
                             modifier = Modifier.visible(fabState?.isVisible ?: false),
                         ) { Icon(Icons.Default.SaveAlt) }
                     },
// ...
) {}

Solution

  • It is specified in the material3 guidelines that the Snackbar should display above the FloatingActionButton.

    spec

    You should not infringe the guidelines. If you want to, you will need to write your own Scaffold, as the placement of the Snackbar is fairly deeply nested in the Composable libraries.