Home > Back-end >  Snackbar is shown behind button in Android kotlin
Snackbar is shown behind button in Android kotlin

Time:01-01

I'm trying to show snackbar without context but it gets hidden behind the system UI buttons, So what to do for the same?

Code :

Snackbar.make(this.vie, message, Snackbar.LENGTH_SHORT)
            .setBackgroundTint(resources.getColor(R.color.blue, null)).show()

Thanks in advance.

CodePudding user response:

Is your window set to no limits(maybe for supporting transparent nav bar)? If so, removing that piece of code can be a fix for now, I guess.

CodePudding user response:

For example you can use setAnchorView method where you will define views according to which you would like to align your snackBar. Some sample below:

Snackbar snackbar = Snackbar.make(view,"Snackbar over BottomNav",Snackbar.LENGTH_INDEFINITE);
    snackbar.setAnchorView(bottomNavigationView);
    snackbar.show();

and also setLayoutParams can be useful:

Snackbar snack = Snackbar.make(findViewById(R.id.coordinatorLayout), 
    "Your message", Snackbar.LENGTH_LONG);
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) 
    snack.getView().getLayoutParams();
params.setMargins(leftMargin, topMargin, rightMargin, bottomBar.height);
snack.getView().setLayoutParams(params);
snack.show();
  • Related