Para cambiar el tinte de los iconos añadidos a un lado de un TextView
JAVA: Compatible Api < 23
private void setTextViewDrawableColor(@RecentlyNonNull TextView textView,@ColorRes int color) {
for (Drawable drawable : textView.getCompoundDrawablesRelative()) {
if (drawable != null) {
drawable.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(textView.getContext(),color), PorterDuff.Mode.SRC_IN));
}
}
}
Use
setTextViewDrawableColor(textView1,R.color.AccentColor)
KOTLIN
private fun setTextViewDrawableColor(@NonNull textView: TextView, @ColorRes color: Int) {
for (drawable in textView.compoundDrawablesRelative) {
if (drawable != null) {
drawable.colorFilter = PorterDuffColorFilter(ContextCompat.getColor(textView.context, color), PorterDuff.Mode.SRC_IN)
}
}
}
Use
setTextViewDrawableColor(textView1,R.color.AccentColor)
KOTLIN EXTENSION
fun TextView.setDrawableColor(@ColorRes color: Int) {
compoundDrawablesRelative.filterNotNull().forEach {
it.colorFilter = PorterDuffColorFilter(ContextCompat.getColor(this.context, color), PorterDuff.Mode.SRC_IN)
}
}
use
textView1.setDrawableColor(R.color.colorAccent)
ONLY XML API => 23
android:backgroundTintMode="src_in"
android:drawableTint="FF0000"