I'm updating my current app to use snackbars, in the Google spec they show various ways of using them http://www.google.com/design/spec/components/snackbars-toasts.html#snackbars-toasts-specs
Example A:
Example B:
Here's my code atm:
Snackbar snackbar = Snackbar.make(mParentLayout, displayMessage,
Snackbar.LENGTH_LONG);
snackbar.setAction(actionMessage, mClickListener);
snackbar.show();
I get the result in Example B,
How can i add margins?
In addition to Saeid's answer, you can get the default SnackBar layout params and modify them as you want:
If you want to apply margin to only specific side(s), you shall also achieve it as below. For example to apply only bottom margin,
Try this:
This works for me
container
is parent tag which is CoordinatorLayoutR.id.bottom_bar
is a view on which above snackbar should be shownif yout want additional margin then simply add padding to
R.id.bottom_bar
. This only worksMy solution in Kotlin extension:
The key to controlling the Snackbar display is using a
android.support.design.widget.CoordinatorLayout
Layout. Without it your Snackbar will always be displayed filled at the bottom on small devices and at the bottom left of large devices. Note: You may use theCoordinatorLayout
as the rootViewGroup
of your layout or anywhere in your layout tree structure.After adding it, ensure you are passing the
CoordinatorLayout
(or child) as the first argument of the Snackbar.make() command.By adding padding or margins to your
CoordinatorLayout
you can control the position and move the Snackbar from the bottom of the screen.The material design guidelines specify a minimum and maximum width of the Snackbar. On small devices you will see it fill the width of the screen, while on tablets you will see the Snackbar hit the maximum width and not fill the width of the screen.