Difference between TextInputLayout and TextInputEditText

前端 未结 3 405
北海茫月
北海茫月 2020-12-29 02:53

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

相关标签:
3条回答
  • 2020-12-29 03:17

    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.

    0 讨论(0)
  • 2020-12-29 03:22

    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.

    0 讨论(0)
  • 2020-12-29 03:37

    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

    0 讨论(0)
提交回复
热议问题