Showing Snackbar on Top (SSoT)

It is mentioned in its documentation that Snackbars provide light feedback about an operation. They display a short message at the bottom of the screen on mobile devices and the bottom left on larger devices.

Is there any other alternative we can use to display the snackbar at the top of the screen instead of the bottom? I am currently confused on how to do it.

Solution

It is very possible to do this, you just need to modify the layout of the Snackbar, here's how.

CoordinatorLayout coordinatorLayout=(CoordinatorLayout)findViewById(R.id.coordinatorLayout);
Snackbar snackbar = Snackbar.make(coordinatorLayout, "Text" , Snackbar.LENGTH_LONG);
View view = snackbar.getView();
CoordinatorLayout.LayoutParams params=(CoordinatorLayout.LayoutParams)view.getLayoutParams();
params.gravity = Gravity.TOP;
view.setLayoutParams(params);
snackbar.show();

Post a Comment

Previous Next

نموذج الاتصال