4

The hint wont float if u set it using data binding

<android.support.design.widget.TextInputLayout
    android:id="@+id/inputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="bottom"
    android:theme="@style/TextAppearance.TextInputLayout.Form"
    >

    <EditText
        android:id="@+id/usernameEditTxt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/default_margin_3"
        android:textSize="16sp"
        android:singleLine="true"
        android:hint="@{model.label}"
        android:inputType="none"
        />
</android.support.design.widget.TextInputLayout>

But if u set the hint manually, it works. Im using Android Studio 3.0 Also using kapt "com.android.databinding:compiler:2.3.3"

Anyone solved this one?

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
iadcialim24
  • 3,817
  • 5
  • 21
  • 32
  • I had the same problem. here is how I fix it https://stackoverflow.com/a/46731803/1930468 – FerdyRod Oct 13 '17 at 14:08
  • You can refer to this post : https://stackoverflow.com/questions/44967669/float-label-hint-textinputlayout-not-works-with-android-data-binding/46731803#46731803. This solution works well. – Shashank Kapsime Apr 27 '18 at 06:46

1 Answers1

1

You have to set the hint attribute on the TextInputLayout.

With Material Components:

 <com.google.android.material.textfield.TextInputLayout
      android:hint="@{viewModel.textHint}"

with old support library:

<android.support.design.widget.TextInputLayout
     android:hint="@{....}"

The reason is that TextInputLayout reads the hint attribute from the TextInputEditText only once (if not specified). After the inflation the changes on the TextInputEditText don't change the TextInputLayout's hint.
With the databinding on the TextInputEditText you are not updating the TextInputLayout for the same reason.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841