32

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

Ashish Dwivedi
  • 8,048
  • 5
  • 58
  • 78

3 Answers3

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.

Budius
  • 39,391
  • 16
  • 102
  • 144
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

yoAlex5
  • 29,217
  • 8
  • 193
  • 205
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.

croxy
  • 4,082
  • 9
  • 28
  • 46
mohammed nathar
  • 190
  • 1
  • 12