Reputation: 3587
I've got a TextView that I want to set the background tint of. My app has a minSDK
of 19
so I've used AppCompatTextView with the app:backgroundTint
parameter used to set the tint declaratively. I would like to programmatically change the tint, but the setSupportBackgroundTintList()
method isn't accessible outside the library group. How can I change this value from an Activity?
Upvotes: 0
Views: 119
Reputation: 54224
From the source code for androidx.appcompat.widget.AppCompatTextView:
This should be accessed via
ViewCompat#setBackgroundTintList(android.view.View, ColorStateList)
So, write this:
AppCompatTextView textView = findViewById(R.id.your_text_view)
ColorStateList colorStateList = ContextCompat.getColorStateList(this, R.color.your_state_list);
ViewCompat.setBackgroundTintList(textView, colorStateList);
Upvotes: 3