TextInputLayout not animating when used as an item of RecyclerView

806 Views Asked by At

I am getting a list of strings from server and should be shown as Hints of TextInputLayout. Everything is working fine, I am getting list of strings from server and based upon the list size I am able to show that many number of views and string values as hint.

The problem I am facing is when they are getting focus, the hint doesn't animate as expected. They looks like a normal EditText.

Below is my code:

layout_input.xml

<android.support.design.widget.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"
    android:paddingTop="8dp"
    android:paddingBottom="8dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

MyViewHolder.kt

internal class InputAttributeHolder(item: View) : RecyclerView.ViewHolder(item) {

    private val attrName: TextInputEditText = item.inputAttr

    fun bind(attr: Attribute) {
        attrName.hint = attr.name
    }
}

NOTE: The hint is set dynamically in ViewHolder while binding, not statically in XML. When I am setting it in XML, it's working fine. But dynamically setting hint doesn't animate.

1

There are 1 best solutions below

0
On

use EditText inside android.support.design.widget.TextInputLayout

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

        <EditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:hint="@string/hint_email"
            android:inputType="textEmailAddress"
            android:textColor="@android:color/white"
            android:textColorHint="@android:color/white" />

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