Is EditText Drawable Tint Impossible?

I use icon shade for my entire application.

An 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 cannot find the code that can be used to tint a picture in EditText . Is it impossible to display stretchable?

Note:

I use the appcompat and design support library but cannot find the code.

+6
source share
4 answers

Use the wrap, setTint, setTintMode from the DrawableCompat class to set the hue for software

 Drawable drawable = getyourdrawablehere; drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, Color.GREEN); DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_OVER); 

And after setting drawable for editText:

 editText.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); 
+25
source

Create a drawable with a raster 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 can use 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" /> 
+8
source

Unfortunately, the solution posted by mbelsky needed very little change. To hone your drawing in your EditText, you need to use wrap setTint and setTintMode . Complete solution for all APIs:

 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); 
+7
source

you can use

 android:drawableTint="@color/yourcolor" 

Please note that it only works on Api 23 or higher.

+2
source

All Articles