Difference between TextInputLayout and TextInputEditText
Asked Answered
B

3

32

Need to know what actually difference between TextInputEditText and TextInputLayout, When should we use one of them.

Boracic answered 15/6, 2016 at 11:9 Comment(0)
I
36

They are different layouts that complement each other functionalities.

  • TextInputLayout extends LinearLayout
  • TextInputEditText extends EditText

They were meant to be used together like following:

<TextInputLayout>
   <TextInputEditText/>
</TextInputLayout>

It's all there on the official docs:

TextInputLayout:

https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html

Layout which wraps an EditText (or descendant) to show a floating label when the hint is hidden due to the user inputting text

TextInputEditText:

https://developer.android.com/reference/android/support/design/widget/TextInputEditText.html

A special sub-class of EditText designed for use as a child of TextInputLayout.

Inquisitive answered 15/6, 2016 at 11:22 Comment(0)
W
2

TextInputLayout vs TextInputEditText

TextInputLayout must contain a TextInputEditText instead of the normal EditText because it designed specially for using inside.

If you add EditText instead of TextInputEditText into TextInputLayout you will get the warning:

EditText added is not a TextInputEditText. Please switch to using that class instead.

For example if you wrap EditText, in Landscape Mode, you will get a big box, but the hint is missing.

TextInputLayout has features as floating hints, error labels, character counter, password visibility, animations and their customization

Westmoreland answered 6/12, 2019 at 19:26 Comment(1)
I didn't see this warning.Spray
S
1

Both TextInputLayout and TextInputEditTextare different. As mentioned in the documentation Here the TextInputLayout and TextInputEditText are meant to be used like the below example(From official doc)

<android.support.design.widget.TextInputLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content">

<android.support.design.widget.TextInputEditText
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:hint="@string/form_username"/>

</android.support.design.widget.TextInputLayout>

Also the main difference is when you compare TextInputEditText with EditText. The TextInputEditText provides a hint when when the layout is viewed in landscape mode. This is explained clearly in depth by TWiStErRob. I hope this answers the question. Thank you.

Spiniferous answered 26/2, 2018 at 6:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.