[TextInputLayout] hintEnabled set to false but hint top space is still claimed
See original GitHub issueDescription: 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: Marked is the mentioned claimed space.
Also from the IDE preview:
With app:hintEnabled="false"
Without app:hintEnabled="false"
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:
- Created 4 years ago
- Reactions:21
- Comments:9 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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 theTextInputLayout
.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.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.