I've seen this new Snackbar Style in the Outlook for Android app and now looked for it in the Material Documentation:
https://material.io/design/components/snackbars.html
Does anybody know how to create those "offset Snackbars"?
Android Snackbar is an interesting component introduced by Material Design. Snackbars are just like Toast messages except they provide action to interact with. Snackbar will be displayed at the bottom of the screen and can be swiped off in order to dismiss them. https://material.io/components/snackbars.
In the onClickListener a Snackbar is created and is called. So whenever the button is clicked, the onClickListener creates a snackbar and calls it and the user sees the message. This snackbar contains an action and if clicked will show a toast.
Snackbars inform users of a process that an app has performed or will perform. They appear temporarily, towards the bottom of the screen. They shouldn't interrupt the user experience, and they don't require user input to disappear.
how to create those "offset Snackbars"?
You can get the LayoutParams
of SnackBar and add Bottom and Side Margin to it
Try out like code below
public static void showSnackbar(Snackbar snackbar, int sideMargin, int marginBottom) {
final View snackBarView = snackbar.getView();
// Depend upon your parent Layout Use `LayoutParams` of that Layout
final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) snackBarView.getLayoutParams();
params.setMargins(params.leftMargin + sideMargin,
params.topMargin,
params.rightMargin + sideMargin,
params.bottomMargin + marginBottom);
snackBarView.setLayoutParams(params);
snackbar.show();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With