question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextInputLayout] hintEnabled set to false but hint top space is still claimed

See original GitHub issue

Description: Setting app:hintEnabled="false" properly hides the hint but keeps the top space where it would normally appear, causing misalignment of components.

Expected behavior: The problem as seen in the Layout Inspector: TextInputLayoutIssue TextInputLayoutIssueMarked Marked is the mentioned claimed space.

Also from the IDE preview: With app:hintEnabled="false" Screen Shot 2020-03-16 at 18 57 50

Without app:hintEnabled="false" Screen Shot 2020-03-16 at 18 58 17

The expected behavior would have been basically the second the “without” visuals but without the animation and the hint.

Source code:

<com.google.android.material.textfield.TextInputLayout
          android:id="@+id/phoneLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginBottom="8dp"
          app:error="An error"
          app:hintEnabled="false"> <!-- This here is the culprit -->

          <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/phoneField"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="03xxxxxxx"
            android:imeOptions="actionNext"
            android:inputType="phone"
            android:maxLength="10"
            android:maxLines="1" />

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

Android API version: From 23 up to recent

Material Library version: 1.2.0-alpha5

Device: Emulators, Pixel 3XL, Pixel 4XL, Samsung S9, S10, others

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:21
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
mt-maddimcommented, Apr 15, 2020

Have the same issue, any workarounds?

@agent10 Yes I have found one actually. After playing around with the Layout Inspector in Android Studio 4 I noticed that the extra space is actually padding to the TextIputEditText inside of the TextInputLayout.

If you override the paddingTop in XML, or with code, you can actually fix that. With default typography I found that a padding of 4 dp is enough to fix it, though I suggest you set both paddingTop and Bottom to make sure you are 100% symmetrical.

3reactions
ParticleCorecommented, Jan 25, 2022

This issue from 2 years ago is still present in 1.6.0-alpha02

Any of the suggested workarounds has always a downside involved, so not a proper solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable/Remove floating label hint text in TextInputLayout XML
But it adds some strange padding on top when you set app:hintEnabled="false" :( If you use icons on the right, it will be...
Read more >
TextInputLayout | Android Developers
Sets whether the hint should expand to occupy the input area when the text field is unpopulated and not focused. void, setHelperText( ...
Read more >
Why My Textinputlayout Always Cuts Off Upper Hint Text In ...
Description: Setting app:hintEnabledfalse properly hides the hint [TextInputLayout] hintEnabled set to false but hint top space is. Not getting cut off just ...
Read more >
Android TextInputLayout Example | DigitalOcean
To disable it we need to add the following attribute inside the tag : app:hintEnabled="false" . The below xml code is from the...
Read more >
TextInputLayout - Android - API Reference Document
Layout which wraps an EditText (or descendant) to show a floating label when the hint is hidden due to the user inputting text....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found