I use tint for icons for whole my app.
Example in my ImageView
:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_account_circle"
android:tint="@color/red_color"/>
I also use some of the icons in EditText
as its drawable:
<EditText
android:id="@+id/passwordInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_lock"
android:drawablePadding="@dimen/medium_margin_padding"
android:hint="@string/password_text"
android:inputType="textPassword" />
However, I can't find any code that can be used to tint the drawable in EditText
. Is it not possible to tint the drawable?
Note:
I use appcompat and design support library, but still can't find any code.
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);
You can use
android:drawableTint="@color/yourcolor"
Note that it only works on Api 23 or higher
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With