Need to know what actually difference between TextInputEditText and TextInputLayout, When should we use one of them.
The main difference between a TextInputLayout and an EditText is that TextInputLayout extends LinearLayout and it must contain TextInputEditText which extends EditText. This is so because TextInputEditText works when enclosed in a TextInputLayout.
↳ com.google.android.material.textfield.TextInputEditText. A special sub-class of EditText designed for use as a child of TextInputLayout . Using this class allows us to display a hint in the IME when in 'extract' mode and provides accessibility support for TextInputLayout .
Android TexInputLayout extends LinearLayout. The primary use of a TextInputLayout is to act as a wrapper for EditText(or its descendant) and enable floating hint animations. Rule of Thumb : TextInputLayout should wrap TextInputEditText instead of the normal EditText.
Now you can simply do input. setError(..) for new error and input. setErrorEnabled(false) to remove it.
They are different layouts that complement each other functionalities.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With