EditText Drawable Tint not possible?
Create a drawable with a bitmap tag like this
drawable_with_tint.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_lock"
android:tint="#fff">
</bitmap>
Then you may use the drawable in your edittext
<EditText
android:id="@+id/passwordInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_drawable_with_tint"
android:drawablePadding="@dimen/medium_margin_padding"
android:hint="@string/password_text"
android:inputType="textPassword" />
Unfortunately the solution posted by mbelsky needed some very small changes. In order to tint your drawable in your EditText you need to use wrap
setTint
and setTintMode
. The full solution for all API's:
Drawable drawable = getResources().getDrawable(drawableID/mipmapID);
emailDrawable = DrawableCompat.wrap(emailDrawable);
DrawableCompat.setTint(emailDrawable,getResources().getColor(R.color.purple));
DrawableCompat.setTintMode(emailDrawable, PorterDuff.Mode.SRC_IN);
editText.setCompoundDrawablesWithIntrinsicBounds(drawable,null,null,null);
Use the wrap, setTint, setTintMode
methods from the DrawableCompat class to set tint for drawable programmatically
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:
editText.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);