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] gravity "top" is not working for hint

See original GitHub issue

Description: Prerequisite: TextInputLayout with TextInputEditText having hint attribute Migrated a layout having design TextInputEditText to material.textfield.TextInputLayout but it is not placing the hint at the top though it was working with support.design.widget and also working for text but not for hint attribute.

Expected behavior: Content hint is placed at the top, see in pic

Minimal Problematic source code:

<com.google.android.material.textfield.TextInputLayout
     android:id="@+id/txtInput"
     app:layout_constraintTop_toTopOf="parent"
     android:layout_width="match_parent"
     android:layout_height="match_parent">

     <com.google.android.material.textfield.TextInputEditText
         android:id="@+id/et_content"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:gravity="top"
         android:hint="@string/et_content_text" />
 </com.google.android.material.textfield.TextInputLayout>

Android API version: 29

Material Library version: com.google.android.material:material:1.2.0-alpha04

Device: Pixel 2 (AVD)

Note: I’ve tested this with alpha04 release, still the same issue issue sample

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

22reactions
leticiarossicommented, Apr 27, 2020

For the filled text field style you have to set android:minLines to 2 or greater for it to work (along with android:gravity="top")

3reactions
ionkotocommented, Apr 2, 2020

@ikim24 Still now working for me…

Android API version: 29

Material Library version: com.google.android.material:material:1.2.0-alpha05

If it helps, setting the TextInputLayout’s attribute hintEnabled=false does put the EditText to the top, but then I am missing the collapsed hint 😕

image image

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set different gravity for TextInputLayout's hint and text ...
To set a different gravity for the EditText , don't set any gravity attributes in the layout, then set the EditText 's gravity...
Read more >
TextInputLayout does not work correctly on multi-line EditText ...
Hint text is not initially visible - Hint text is always vertically centered instead of respecting gravity (gravity=top should display hint text at...
Read more >
TextInputLayout | Android Developers
Returns whether the hint expands to occupy the input area when the text field is unpopulated and not focused. boolean, isHelperTextEnabled().
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 >
TextInputEditText how can align hint to the top margin - Reddit
Why ? Instead i'm not encounter this problem with com.google.android.material:material:1.1.0-beta02. This is my ...
Read more >

github_iconTop Related Medium Post

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