Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set tint of EditText error icon

Is there a way to set or change the tint of the EditText error icon? it is red with an exclamation mark. I want to set or change the tint to a color of my choosing.

like image 324
learner Avatar asked Oct 18 '22 23:10

learner


1 Answers

I don't think there is an easy way to change the tint color without replacing the icon. Fortunately, the material icon set in Android Studio -> Vector Asset -> Clip Art provide an error icon which looks similar.

val icon = AppCompatResources.getDrawable(context, R.drawable.ic_error_black_24dp)

// change icon color
DrawableCompat.setTint(icon, Color.parseColor("#F6CECE"))

// this is necessary, else icon won't show
icon.setBounds(0, 0, icon.intrinsicWidth, icon.intrinsicHeight)

// setError
editText.setError(getString(R.string.validation_required), icon)

https://code.luasoftware.com/tutorials/android/android-edittext-custom-seterror-icon/

like image 164
Desmond Lua Avatar answered Oct 21 '22 17:10

Desmond Lua