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] Allow hint to float always

See original GitHub issue

Is your feature request related to a problem? Please describe. Currently it is impossible to set a hint to both TextInputLayout and TextInputEditText without both overlapping, in some cases it would be nice to show both hints to the user.

Describe the solution you’d like Create an attribute such as:

android:hintAlwaysFloat="true"

Or something like it.

Describe alternatives you’ve considered The easiest alternative to achieve such design is to set a TextView and an EditText within a container and handle both of them.

I’ve also seen the use of reflection to achieve such behaviour, however this brings undesired problems.

Additional context Actual:

<com.google.android.material.textfield.TextInputLayout
            android:id="@+id/input"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Name">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="e. g. Mauro N."
                android:inputType="text"/>

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

image

Suggested:

<com.google.android.material.textfield.TextInputLayout
            android:id="@+id/input"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Name"
            android:hintAlwaysFloat="true">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="e. g. Mauro N."
                android:inputType="text"/>

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

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:19
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

11reactions
dsn5ftcommented, Oct 22, 2020

We added support for this in https://github.com/material-components/material-components-android/commit/22973ff10305397bfc72fed41684175fee8aeefb via the new expandedHintEnabled attribute, available in version 1.3.0-alpha03.

7reactions
zx2c4commented, Apr 2, 2020

Afaict, placeholderText only shows both when selected, which is bot what you want. https://github.com/material-components/material-components-android/pull/1163 contains a proper (and trivial) fix to make hints always work as desired.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Keep Textinputlayout hint always top - Stack Overflow
Here's a hack - programmatically add a space in the text if it's empty. However, you would then have to remove the space...
Read more >
TextInputLayout | Android Developers
Layout which wraps a TextInputEditText , EditText , or descendant to show a floating label when the hint is hidden while the user...
Read more >
Android TextInputLayout Example | DigitalOcean
Floating Hints are enabled by default in a TextInputLayout. To disable it we need to add the following attribute inside the tag :...
Read more >
Floating Labels In EditText TextInputLayout Android
It takes the value of hint assigned to EditText and displays it as floating label. Android Design Support Library introduced some important new...
Read more >
TextInputLayout hint does not support Span [37076105]
textInputLayout.setHint(hint); TextInputLayout uses internal class CollapsingTextHelper to draw the hint, which does not support spans.
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