Android floating label effect no working on TextInputLayout using databinding

Viewed 552

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?

1 Answers

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.

Related