How to set support library snackbar text color to something other than android:textColor?

前端 未结 22 2299
温柔的废话
温柔的废话 2021-01-30 12:33

So I\'ve started using the new Snackbar in the Design Support Library, but I found that when you define \"android:textColor\" in your theme, it applies to the text color of the

22条回答
  •  有刺的猬
    2021-01-30 12:46

    Created this kotlin extention function i use in my projects:

    fun Snackbar.setTextColor(color: Int): Snackbar {
        val tv = view.findViewById(com.google.android.material.R.id.snackbar_text) as TextView
        tv.setTextColor(color)
    
        return this
    }
    

    Usage like you would expect:

    Snackbar.make(view, R.string.your_string,Snackbar.LENGTH_LONG).setTextColor(Color.WHITE).show()

提交回复
热议问题