Add margins to Snackbar view

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

    None of the above solutions worked for me. This is my solution, my idea is create the background with transparent side, so looks like a margin. Try this works for me:

    1. Create drawable for background

       
       
           
               
                   
               
           
           
               
                   
                   
               
           
       
      
    2. Using kotlin extension to show Snackbar and add the padding

       private fun Snackbar.show(context: Context) {
           this.view.setPadding(Dpx.dpToPx(16), Dpx.dpToPx(16), Dpx.dpToPx(16), Dpx.dpToPx(16))
           this.view.background = context.getDrawable(R.drawable.bg_snackbar)
           show()
       }
      
    3. Call Snackbar make

       Snackbar.make(view, R.string.my_message, Snackbar.LENGTH_SHORT).show(this)
      

    Thats all. Tell me if that works, thanks...

提交回复
热议问题