Android TextView DrawableTint on pre v23 devices
AndroidX appcompat library supports tinting in TextView since version 1.1.0-alpha03 [ref].
Add dependencies to appcompat library
dependencies {
implementation "androidx.appcompat:appcompat:1.1.0"
}
Then drawable in TextView can be tinted from XML like this
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:drawableStartCompat="@drawable/ic_plus"
app:drawableTint="@color/red" />
Don't forget to include
xmlns:app="http://schemas.android.com/apk/res-auto"
and to extend your Activity from AppCompatActivity
.
The programmatic way to do this is
Drawable[] drawables = textView.getCompoundDrawables();
if (drawables[0] != null) { // left drawable
drawables[0].setColorFilter(color, Mode.MULTIPLY);
}
This works for all API levels.
This is your best option for pre-Marshmallow devices.