4

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

jafarbtech
  • 6,842
  • 1
  • 36
  • 55
  • I am not sure but can you try this? Drawable drawable = getyourdrawablehere; drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, Color.GREEN); DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_OVER); And after set the drawable for the editText: textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); – mihir raj May 20 '17 at 07:50
  • @mihirraj the drawable is not setting. No error. but it does nothing – jafarbtech May 20 '17 at 10:05

3 Answers3

10

This works for me

someTextView.getBackground().setTint(yourIntColor);
Martin Olariaga
  • 379
  • 4
  • 4
3

Note

Added in version 23.1.1 So you can't use in 19

For AppCompat , You can use setSupportButtonTintList

void setSupportButtonTintList (ColorStateList tint)

tvOBJ.setSupportButtonTintList(ContextCompat.getColorStateList(CurrentActivity.this, R.color.your_color));
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

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)