show snackbar above bottomnavigationview navigation component code example

Example 1: show snackbar above bottomnavigationview navigation component

private fun showSnackBarMessage() {
    val bottomNavView: BottomNavigationView = activity?.findViewById(R.id.bottom_nav)!!
    Snackbar.make(bottomNavView, "No data available", Snackbar.LENGTH_SHORT).apply {
        anchorView = bottomNavView
    }.show()
}

Example 2: android snackbar message is behind back button

FloatingActionButton fab = findViewById(R.id.fab);
Snackbar snackbar = Snackbar.make(view, "Snackbar over BottomAppBar", Snackbar.LENGTH_LONG);
snackbar.setAnchorView(fab);

Tags:

Java Example