I\'m using the new TextInputLayout provided by Android.support to do floating label. But it will fail Espresso Accessibility Check because \"View is missing speakable text n
Hints aren't great for accessibility in general. They disappear when text is entered. Try using a "LabelFor" instead. If you don't want a visible label, you can set your label to not be displayed.
This app will give you hints on how to make text boxes accessible.
https://play.google.com/store/apps/details?id=com.dequesystems.accessibility101
You can make a TextView that has
android:text="My Announcement For Edit Text"
android:labelFor="@id/my_edit_text".
Visibility = gone
and visibility = invisible
will make it so this label is not announced. Also if you set height and width to 0dp, this will not announce. Instead, constrain the view to be off the screen using something like:
app:layout_constraintEnd_toStartOf="parent"
So your textview will look like this:
<TextView
android:id="@+id/edit_text_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@+id/my_edit_text"
android:text="Label For My Edit Text"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
A great way to make TextInputLayout accessible is to use "LabelFor" as recommanded by ChrisCM, but you don't have to add an invisible label view to do so: Just put the labelFor
or your Textinputlayout
and make it point to your EditText
Example:
<android.support.design.widget.TextInputLayout
android:labelFor="@+id/username"
android:contentDescription="@string/username_hint"
android:accessibilityLiveRegion="polite">
<edittext
android:id="@+id/username"
android:hint="@string/username_hint"
…/>
</android.support.design.widget.TextInputLayout>
This way you get the exact same visual behaviour and make "Espresso Accessibility Check" and Talkback happy :)
(To make TextInputLayout fully accessible I also added android:accessibilityliveregion
on the TextInputLayout element to trigger talkback whenever the error is poping)
A big thanks to this post this blog post which helped a lot
Alternatively, if this is a false positive you can ignore checks as described here
val validator: AccessibilityValidator = AccessibilityChecks.enable().apply {
setSuppressingResultMatcher(
allOf(
matchesCheckNames(`is`("TouchTargetSizeViewCheck")),
matchesViews(withId(R.id.my_overflow))
)
)}
The following rules are invoked when we enable tests for accessibility checks: