invalid-labeling-attribute
Ensure that you are using only valid labeling attributes or methods .
Description
Text input fields usually require specific labeling attributes or methods to correctly announce both the label (accessible name) and the value, so they are understandable for all users.
Quick Fixes
When using an ImageView, ImageButton, CheckBox, or other View that conveys information graphically, use an android:contentDescription attribute to provide a content label for that View. For EditTexts or editable TextViews, use an android:hint attribute to indicate the purpose of the text field. An android:contentDescription should not be used as a content label for editable Views.
Android (.xml):
Pass
1✓ <EditText2 android:id="@+id/firstNmaeField"3 android:layout_width="match_parent"4 android:layout_height="wrap_content"5 android:hint="First Name"/>
1✓ <LinearLayout2 android:layout_width="match_parent"3 android:layout_height="match_parent"4 android:orientation="vertical">5 <TextView6 android:layout_width="match_parent"7 android:layout_height="wrap_content"8 android:text="First Name"9 android:labelFor="@id/firstNmaeField" />10 <EditText11 android:id="@+id/firstNmaeField"12 android:layout_width="wrap_content"13 android:layout_height="wrap_content" />14</LinearLayout>
1✓ <AutoCompleteTextView2 android:id="@+id/foodSelectCombo"3 android:layout_width="match_parent"4 android:layout_height="wrap_content"5 android:hint="What is your favorite food?"/>
Fail
1✗ <EditText2 android:id="@+id/firstNmaeField"3 android:layout_width="match_parent"4 android:layout_height="wrap_content"5 android:contentDescription="First Name"/>
1✗ <AutoCompleteTextView2 android:id="@+id/foodSelectCombo"3 android:layout_width="match_parent"4 android:layout_height="wrap_content"5 android:contentDescription="What is your favorite food?"/>
Android (Java):
Pass
1✓ EditText editText = new EditText(this);2 editText.setHint("First Name");
1✓ TextView label = new TextView(this);2 label.setText("First Name");34 EditText editText = new EditText(this);56 label.setLabelFor(editText.getId());
Fail
1✗ EditText editText = new EditText(this);2 editText.contentDescription("First Name");
How Users Are Affected
Some assistive technologies, especially screen readers, may read the label differently or out of order, so users may not understand it accurately and sometimes may not hear it at all.
WCAG Success criteria
4.1.1 parsing (A)