1

I am using basic TextInputLayout. I am setting error when EditText is empty. When user enters some text, I am removing error text like this.

 tilPassword.isErrorEnabled = false
 tilPassword.error = null

This is working fine and good. The reason for calling tilPassword.isErrorEnabled = false is that it is helping me to remove extra space that TextInputLayout adds to the layout when showing error texts. When user enters some text, I am removing error and also the extra space (that is added by TextInputLayout) as well.

Error message is being removed but extra space is not getting removed in Android 9.0. How to solve this issue?

Azizjon Kholmatov
  • 1,136
  • 1
  • 13
  • 26

1 Answers1

4

https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout.html#setErrorEnabled(boolean)

The docs explain:

Enabling this functionality before setting an error message via setError(CharSequence), will mean that this layout will not change size when an error is displayed.

So it would work like so.

Show an error:

tilPassword.setErrorEnabled(true)
tilPassword.setError("Wrong password")

Hide an error:

tilPassword.setError("")
tilPassword.setErrorEnabled(false)

Ensure that you are using the AndroidX version of TextInputLayout:

https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout.html

As the platform version below is deprecated:

https://developer.android.com/reference/android/support/design/widget/TextInputLayout

Ref. someone explaining the source:

https://stackoverflow.com/a/35162822/413127

Blundell
  • 75,855
  • 30
  • 208
  • 233
  • 1
    Yes I have tried exactly like this. Unfortunately, not working. I created a sample project just to check this functionality and, to my surpise, it is working on the sample project. I am trying to further investigate what might also be affecting this behavior. I will update my question after some time. – Azizjon Kholmatov Jan 29 '20 at 09:35
  • Also, I am using `androidx` version of the `TextInputLayout`. – Azizjon Kholmatov Jan 29 '20 at 09:46
  • Hi, did investigation for the last couple of hours. I think the problem is with something else. I created a sperate question. Could you please check it out? – Azizjon Kholmatov Jan 29 '20 at 14:13
  • https://stackoverflow.com/questions/59968915/transition-in-motionlayout-causing-textinputlayout-seterror-message-not-work-in – Azizjon Kholmatov Jan 29 '20 at 14:13