我在自定义MaterialEditText上出现视觉异常。我修改了onDraw以显示字段验证器(是否有效的电子邮件地址)。您是否有解决此问题的途径?
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
conditions.forEach {
val predicate = it.predicate(text.toString())
val pen = when {
showErrorIfNeeded && !predicate && !text.isNullOrEmpty() -> redPen
predicate && !text.isNullOrEmpty() -> greenPen
else -> greyPen
}
val icon = when {
showErrorIfNeeded && !predicate && !text.isNullOrEmpty() -> errorIcon
predicate && !text.isNullOrEmpty() -> okIcon
else -> nokIcon
}
val label = if (showErrorIfNeeded && !predicate) it.errorLabel else it.normalLabel
canvas.withTranslation(x = scrollX.toFloat(), y = scrollY.toFloat()) {
drawText(label,
it.position.left + conditionIconHorizontalSpace,
it.position.top + (height - saveViewHeightExtra) + conditionLineHeight + conditionMargin,
pen)
drawBitmap(icon,
it.position.left,
it.position.bottom + (height - saveViewHeightExtra) - icon.height + conditionMargin,
bitmapPaint)
}
}
}