Skip to content

Instantly share code, notes, and snippets.

@nicemak
Forked from ibrahim-mrq/isTextMoreThan.kt
Created December 7, 2024 04:41
Show Gist options
  • Save nicemak/b8512e7e7603cddb090d8f17070b0b2d to your computer and use it in GitHub Desktop.
Save nicemak/b8512e7e7603cddb090d8f17070b0b2d to your computer and use it in GitHub Desktop.
fun isTextMoreThan(editText: EditText, charNumber: Int): Boolean {
return if (editText.text.toString().length >= charNumber) {
editText.background =
ContextCompat.getDrawable(requireContext(), R.drawable.shape_edit_text)
editText.background.alpha = 180
true
} else {
editText.background = ContextCompat.getDrawable(
requireContext(),
R.drawable.shape_edit_text_error
)
editText.error =
"${getString(R.string.password_must_than)} $charNumber characters"
editText.background.alpha = 180
false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment