How to change background color of the snackbar?

后端 未结 16 626
温柔的废话
温柔的废话 2020-12-07 19:28

I am showing snackbar in DialogFragment Within the Positive click of alertDialog. Here is my code snippet.

Snackbar snackbar = Snackbar.make(view, \"Please e         


        
16条回答
  •  醉梦人生
    2020-12-07 20:10

    Kotlin version (with an extension) :

    Create in a file (for exemple SnackbarExtension.kt) an extension :

    fun Snackbar.withColor(@ColorInt colorInt: Int): Snackbar{
       this.view.setBackgroundColor(colorInt)
       return this
    }
    

    Next, in your Activity/Fragment, you'll be able to do this :

    Snackbar
      .make(coordinatorLayout, message, Snackbar.LENGTH_LONG)
      .withColor(YOUR_COLOR)
      .show()
    

提交回复
热议问题