apollow apollow - 1 year ago 106
Android Question

How do I change an Android Snackbar's initial alignment from bottom to top?

The recent android library came out just a few days ago, but I would like to have the

appear on top of the screen, preferably within a RelativeLayout as it's parent view.

How does one change the
's initial alignment which I presume to be

Answer Source

It is possible to make the snackbar appear on top of the screen using this:

Snackbar snack = Snackbar.make(parentLayout, str, Snackbar.LENGTH_LONG);
View view = snack.getView();
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)view.getLayoutParams();
params.gravity = Gravity.TOP;

Note: The animation from the snackbar begins from the bottom and surges up to the top of the screen as expected because it was intended to be in the bottom due to ianhanniballake's answer.

For notifications surging from the top, it would probably better off getting a Custom banner instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download