Add margins to Snackbar view

前端 未结 17 1461
时光取名叫无心
时光取名叫无心 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 16:55

    This works for me
    container is parent tag which is CoordinatorLayout
    R.id.bottom_bar is a view on which above snackbar should be shown

        Snackbar.make(container, getString(R.string.copied), Snackbar.LENGTH_LONG).apply {
            val params = view.layoutParams as CoordinatorLayout.LayoutParams
            params.anchorId = R.id.bottom_bar
            params.anchorGravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
            params.gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
            view.layoutParams = params
            show()
        }
    

    if yout want additional margin then simply add padding to R.id.bottom_bar. This only works

提交回复
热议问题