Material-components-android: When I use TextInputLayout (whose hintEnabled is false and style is OutLinedBox ), it seems to be clipped

Created on 31 Jul 2018  路  11Comments  路  Source: material-components/material-components-android

When I use TextInputLayout (whose hintEnabled is false and style is OutLinedBox ), it seems to be clipped

Requirement

I want TextInputLayout's height is same as When it's hintEnabled is true, but don't show the lable(hint) on TextInputLayout, and the hint be shown in EditText

code in xml

<android.support.design.widget.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:hintEnabled="false"
        >
        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="12312312312"
            />
    </android.support.design.widget.TextInputLayout>

result

2018-07-31 8 47 44

it seems that the Input's bound clipped

result I want

2018-07-31 8 49 32

Most helpful comment

if you have used app:hintEnabled="false" then also set android:paddingTop="8dp" in EditText and boom top hint space is gone, this worked for me hope this works for you too

All 11 comments

@amiyo-biswas it doesn't work, I had already followed it

Looking at the source code, the layout adds additional top margin if hintEnabled is true, else it completely ignores adding any top margin.

Don't know why they coded it like that, the top edge of the view is still there regardless if the hint is enabled or not. If that method (and the methods that call that method) weren't private, it'd be a simple fix to just ignore checking if hintEnabled is true or not, but those methods being private complicates things for us end-users.

+1 Having this issue as well.

In my case, if set hint for TextInputEditText programmatically then floating label not showing.

This issue is being looked at with https://issuetracker.google.com/issues/111959880

Also error text looses its top margin in this scenario

Closing this issue, please follow https://issuetracker.google.com/issues/111959880 instead.

Looking at the source code, the layout adds additional top margin if hintEnabled is true, else it completely ignores adding any top margin.

Don't know why they coded it like that, the top edge of the view is still there regardless if the hint is enabled or not. If that method (and the methods that call that method) weren't private, it'd be a simple fix to just ignore checking if hintEnabled is true or not, but those methods being private complicates things for us end-users.

You saved my life! 4 years+, still wonder why Android development has to be this hard!

if you have used app:hintEnabled="false" then also set android:paddingTop="8dp" in EditText and boom top hint space is gone, this worked for me hope this works for you too

if you have used app:hintEnabled="false" then also set android:paddingTop="8dp" in EditText and boom top hint space is gone, this worked for me hope this works for you too

Wow thank you so much!

Was this page helpful?
0 / 5 - 0 ratings