Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText Drawable Tint not possible?

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.

like image 622
Rendy Avatar asked Oct 22 '15 02:10

Rendy


2 Answers

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);
like image 138
mbelsky Avatar answered Sep 28 '22 04:09

mbelsky


You can use

android:drawableTint="@color/yourcolor"

Note that it only works on Api 23 or higher

like image 26
p_0g_amm3_ Avatar answered Sep 28 '22 04:09

p_0g_amm3_