Android EditText Custom SetError Icon (Kotlin)

April 20, 2018
// load icon, works for vector
// val icon = ContextCompat.getDrawable(context, R.drawable.ic_error_black_24dp)
val icon = AppCompatResources.getDrawable(context, R.drawable.ic_error_black_24dp)

// change icon color
// DrawableCompat.setTint(icon, ContextCompat.getColor(context, R.color.icon_tint))
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)
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.