How to show Snackbar at top of the screen

后端 未结 9 1659
梦谈多话
梦谈多话 2020-12-02 07:33

As the Android documentation says

Snackbars provide lightweight feedback about an operation. They show a brief message at the bottom

9条回答
  •  时光取名叫无心
    2020-12-02 08:33

    This makes the Snackbar appears on Top without the strange slide in transition.

    Best simple solution in Kotlin:

        val snackbar = Snackbar.make(view, string, Snackbar.LENGTH_LONG)
        val layoutParams = LayoutParams(snackbar.view.layoutParams)
    
        layoutParams.gravity = Gravity.TOP
        snackbar.view.setPadding(0, 10, 0, 0)
        snackbar.view.layoutParams = layoutParams
        snackbar.animationMode = BaseTransientBottomBar.ANIMATION_MODE_FADE
        snackbar.show()
    

提交回复
热议问题