Add margins to Snackbar view

前端 未结 17 1463
时光取名叫无心
时光取名叫无心 2020-12-06 16:20

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#sna

17条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 17:05

    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 the CoordinatorLayout as the root ViewGroup 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.

提交回复
热议问题