Android - TextInputLayout doesn't wrap hint of TextInputEditText

textinputlayout androidx dependency
customize textinputlayout android
android textinputlayout clear button
textinputlayout error
com.google.android.material.textfield.textinputlayout not working
textinputlayout error icon
com.google.android.material.textfield.textinputlayout hint color
android edittext style

I have a simple TextInputEditText nested in TextTnputLayout.

I am trying to make the of TIL to be as long as the hint given in TIET.

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

    <android.support.design.widget.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="This is a hint"/>

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

But the problem is, it doesn't show anything

I have to set TIL's width to match_parent or just any other width other than wrap_content. But I want to the width to be dynamic as in, the width of TIL follows the length of the hint provided. Is it possible? If yes, how to do that?

I am using support library version 26.0.2 btw.

Yvette Colomb's answer is close, the TIL wraps the TIET but the fancy animation doesn't work there. It might be because the animation won't start if hints are set in execution?

You can do so, by setting the hint in the java code.

Remove the hint from the xml:

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

    <android.support.design.widget.TextInputEditText
        android:id="@+id/inputTxt"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

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

Declare and initialise the TextInputEditText in the activity and set the hint.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final TextInputEditText inputTxt = (TextInputEditText) findViewById(R.id.inputTxt);
    inputTxt.setHint("This is a hint");
}

This will wrap the text to the width of the hint as you type (not saying this is how it goes for all devices)

Then expand the width when you've entered the text.

To answer your updated question.

How to make the input layout grow as we enter input.

<android.support.design.widget.TextInputLayout
    android:id="@+id/txtInputL"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.TextInputEditText
        android:id="@+id/inputTxt"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:maxLines="1"/>

The Java.

final TextInputEditText inputTxt = (TextInputEditText) findViewById(R.id.inputTxt);
inputTxt.setHint("This is a hint");
final TextInputLayout txtInputL = (TextInputLayout) findViewById(R.id.txtInputL);
txtInputL.setMinimumWidth(300);
txtInputL.setHint("This is a hint");

I've added a floating hint:

As we're typing:

If you have any other questions about this, please ask a new question.

Android TextInputLayout Example, Description: Seem like TextInputLayout is not getting focus when typeing text (​The TextInputEditText does getting focused just TextInputLayout doesn't). This problem is TextInputLayout android:id="@+id/textLayout"  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.

You can achieve this from xml instead, just set the hint for both TextInputLayout and TextInputEdittext and it will work then to make the TextInputEdittext grow as you are typing you have to set the it maxlines="1" and the layout_height to wrap_content as below

 <android.support.design.widget.TextInputLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="This is edittext">

            <android.support.design.widget.TextInputEditText
                android:hint="This is edittext
                android:maxLines="1"
                android:inputType="numberDecimal"
                android:layout_width="wrap_content"
                android:layout_height="match_parent" />

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

I hope this help someone

Text Fields, MockView cannot be cast to android.view.ViewGroup Exception details are logged in Window >  Text fields. Text fields let users enter and edit text.. Contents. Using text fields; Filled text field; Outlined text field; Theming; Using text fields. Before you can use Material text fields, you need to add a dependency to the Material Components for Android library.

Try doing this.

 <android.support.design.widget.TextInputEditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="This is a hint"/>

Android TextInputLayout Tutorial, In this video we will learn, how to use the TextInputLayout together with the TextInputEditText Duration: 15:18 Posted: Mar 24, 2018 I think you're mixing view groups. The attributes width/height are there so a widget can inform its parent how much space it needs; whether the parent can accommodate for this or not, is a different story to be resolved after onMeasure + onLayout… so a ConstraintLayout does not support widgets telling it that they need to MATCH_PARENT; they can, however, say they want to match their

Try this:

<android.support.design.widget.TextInputLayout
                android:id="@+id/txt_inputLayout_gify"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/edt_gift_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="This is hint." />
            </android.support.design.widget.TextInputLayout>

Customizing TextInputLayout - Part 1, Google I/O 2015 was an important event for every Android developer and A TextInputLayout widget behaves exactly as a LinearLayout does,  As I said, TextInputLayout is just a wrapper, but unlike LinearLayout and ScrollView, you can get its child element using a specific method, getEditText. There's no need to use findViewById. If TextInputLayout doesn't contain an EditText, getEditText returns null so be careful of a NullPointException.

[TextInputLayout] TextInputLayout not getting focus · Issue #879 , The EditText is the standard text entry widget in Android apps. If the user needs to enter text into an app, this is the primary way for them to do that. EditText. There  ldjcmu changed the title [TextInputLayout] boxStrokeColor only change the focused color on Outlined box [TextInputLayout] boxStrokeColor doesn't work with ColorStateLists for a variety of states. Oct 1, 2019

android.support.design.widget.TextInputLayout could not be , Before getting into example, we should know what is TextInputLayout in android. TextInputLayout is extended by Linear Layout. It going to act  Okay, so I created a simple app in android then refactored it to androidx. The tags seem to be changed <com.google.android.material.textfield.TextInputLayout and <com.google.android.material.textfield.TextInputEditText and it doesn't need the extra dependency, so long as there's implementation 'com.google.android.material:material:1.0.0'

TextInputLayout (Floating Label EditText), TextInputLayout is one such component which adds a wrapper around standard edittext widget thereby improving handling of hint text and error text. Styling TextInputLayout and TextInputEditText on Android by the encompassing TextInputLayout (why Android, why have to spend 3 hours trying to style a Widget that doesn't work out of the

Comments
  • I don't write anything in Java, it's a test layout
  • Try simple EditText insted of TextInputEditText and set EditTextHeight matchparent
  • At first I was using EditText, and tried all possible match_parent
  • What ypu want exactly?
  • Have you given layout_weight to its parent layout in height attribute ??
  • Ohh that's almost right to my need actually! I also need the text hint to be animated though, as this defeats the purpose of TIL :(.. I should add more info to the question
  • No, that cute animation when user enters a letter and the hint moves up so that I don't need to use TV above ET to show user which field they are inputting like normal form..
  • Oh! So it's different?? I thought it's the same, because that's basically what TIL does lol, okay I've now adjusted the length on the ETs depending on screen size though, so no need for another question just yet, thanks!
  • This didn't answer my question, but it was close though, I thought that upvote was from me so I didn't upvote lol, here, take another upvote!
  • This doesn't work.. I tried it, and I just tried it again lol, and it still doesn't work :(
  • I have to make TIL to match_parent?
  • @ShwetaChauhan It will work, yes.. I know, but.. I asked about dynamic width TIL following its hint length, so by making it match_parent doesn't help.. :(