Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInputLayout, setError increases height

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?

like image 417
Stack Diego Avatar asked Nov 27 '25 07:11

Stack Diego


1 Answers

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.

like image 145
Stack Diego Avatar answered Nov 28 '25 22:11

Stack Diego