1
0
Fork 0

Clear button (#13842)

Co-authored-by: Darren <finchdarren25@gmail.com>
master
Kainalu Hagiwara 2020-08-14 09:48:46 -07:00 committed by GitHub
parent 88f01731d7
commit afd0af1075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -46,7 +46,9 @@ class ClearableEditText @JvmOverloads constructor(
* Displays a clear icon if text has been entered.
*/
override fun onTextChanged(text: CharSequence?, start: Int, lengthBefore: Int, lengthAfter: Int) {
val drawable = if (shouldShowClearButton(lengthAfter)) {
// lengthAfter has inconsistent behaviour when there are spaces in the entered text, so we'll use text.length.
val textLength = text?.length ?: 0
val drawable = if (shouldShowClearButton(textLength)) {
AppCompatResources.getDrawable(context, R.drawable.ic_clear)?.apply {
colorFilter = createBlendModeColorFilterCompat(context.getColorFromAttr(R.attr.primaryText), SRC_IN)
}