Skip to main content
Logo Appt Light

Input label on Android

Input fields should have labels so that users know what input data is expected. These labels should stay visible while users are entering data. A placeholder which disappears while entering data does not count as a label.

On Android, you can link labels to controls by using the labelFor attribute. We recommend using a TextView to show labels for input fields.

You can also use TextInputLayout, which allows you to create an input field with a label. The hint property at the TextInputLayout level is used as visual label. The hintEnabled and expandedHintEnabled properties must be set to true to always show the label.

<TextView android:text="Name" android:labelFor="@+id/field"/>
<EditText id="@+id/field" hint="Enter your name"/>

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:hintEnabled="true"
    app:expandedHintEnabled="true"
    android:hint="Name">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter your name"/>
</com.google.android.material.textfield.TextInputLayout>

Feedback?

Let us know!