3

I have a simple TextInputLayout:

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/tilPwd"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Passcode"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" >

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:singleLine="true" />

</com.google.android.material.textfield.TextInputLayout>

Then I have other views below.

The issue is that when I set the error on the TextInputLayout the height increases and pushes all the views below. I tried a workaround setting a blank helperText, but when in talkback the blank helperText will be read and that's not what I want.

Is there a clean solution other then wrapping the TextInputLayout in some ViewGroup with a set height?

Stack Diego
  • 1,309
  • 17
  • 43

3 Answers3

2

After a day of tries, I actually found the solution:

public void setHelperTextEnabled (boolean enabled)

Whether the helper text functionality is enabled or not in this layout. Enabling this functionality before setting a helper message via setHelperText(CharSequence) will mean that this layout will not change size when a helper message is displayed.

Basically it occupies in advance the space of the helperText (even if it's not set), and that's the same space occupied from the error.

Worth to notice that the equivalent xml attribute "app:helperTextEnabled" does not solve the issue.

Stack Diego
  • 1,309
  • 17
  • 43
1

Yes, When you enable the error attribute of TextInputLayout, it will always increase the height of the View to show the error(whenever occurred), which will cause other Views/ViewGroups to push further below.

What you can do to get rid of the extra space is set the error programmatically.

For example, whenever an error occurred(or whenever if you want to set the error) you can call

setErrorEnabled(boolean value) 

so that it can also show the error and will push other views down (which are below it), and if the error is gone(or you want to hide error), then you can call

setError("")

where you need to pass an empty string and then call the setErrorEnabled(false), so the textInputLayout will come back to its original position.

Stack Diego
  • 1,309
  • 17
  • 43
Vicious
  • 11
  • 2
0

I had the same problem and solved it by adding this XML attribute.

app:errorEnabled="true"