how to set `app:backgroundTint` for Textview programatically?

Viewed 4586

I am trying to add tint to my normal Textview not AppCompatTextView. I can add backgroundTint in xml using app:backgroundTint for it. Is there a way to do the same programatically for Textview itself.(I am targeting kitkat support)

Note: I have more Textview. so changing all of them will be over work

setSupportButtonTintListonly works for AppCompat controls. setBackgroundTintList shows no result in kitkat

3 Answers

This works for me

someTextView.getBackground().setTint(yourIntColor);

You can use ViewCompat.setBackgroundTintList()

    val states = arrayOf(intArrayOf(android.R.attr.state_enabled))
    val colors = intArrayOf(Color.RED)
    val colorStateList = ColorStateList(states, colors)

    ViewCompat.setBackgroundTintList(myView, colorStateList)
Related