How to use Snackbars

A Snackbar is a replacement for Toasts in Android.

Dependency

implementation 'com.google.android.material:material:1.4.0'

Layout

A snackbar must be tied to a coordinator layout. If you use fragments the standard layout is FrameLayout which can be directly swapped with:

<androidx.coordinatorlayout.widget.CoordinatorLayout

Snackbar

val snackbar =
    Snackbar.make(
        binding.root,
        "No internet connection! Please enable WiFi or Mobile Data",
        Snackbar.LENGTH_INDEFINITE
    )
snackbar.show()