androidtexthint

Android EditText view Floating Hint in Material Design


Does API 21 provide a method to use the following feature:

http://www.google.com/design/spec/components/text-fields.html#text-fields-floating-labels

I'm trying to float the EditText hints.

Thanks!


Solution

  • You need to add the following to your module build.gradle file:

    implementation 'com.google.android.material:material:1.0.0'
    

    And use com.google.android.material.textfield.TextInputLayout in your XML:

           <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/text_input_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/my_hint">
    
            <EditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="UserName"/>
       </com.google.android.material.textfield.TextInputLayout>