Raj
Raj

Reputation: 22956

SnackBar goes behind other views

I am trying to show a Snackbar in my activity. But it is being shown behind other views in the activity. How to show it as a top view?

Snackbar snack = Snackbar.make(referenceView, referenceView.getContext().getString(messageId), showLength);
snack.show();

referenceView is nothing but a label in the same activity.

enter image description here

Upvotes: 3

Views: 711

Answers (1)

Make sure that your referenceView is instance of CoordinatorLayout, otherwise the Snackbar will anchor to a system view.

Per the Snackbar docs regarding the view parameter:

Snackbar will try and find a parent view to hold Snackbar's view from the value given to view. Snackbar will walk up the view tree trying to find a suitable parent, which is defined as a CoordinatorLayout or the window decor's content view, whichever comes first.

Upvotes: 1

Related Questions