Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessibility Check fail when using TextInputLayout

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 needed for a screen reader".

Looked into it and find out the TextInputLayout will nullify hint when parent does addView(). This is basically how it can float the label up(set the label, nullify the hint). And any EditText with null hint will fail the accessibility check.

Anyone knows how to resolve this issue? It's really driving me crazy..

Thanks a lot!!!!

like image 737
StarDust Avatar asked Jun 11 '15 01:06

StarDust


People also ask

How do I remove TextInputLayout error?

setError(..) for new error and input. setErrorEnabled(false) to remove it.

What is the use of TextInputLayout in Android?

The primary use of a TextInputLayout is to act as a wrapper for EditText(or its descendant) and enable floating hint animations. Rule of Thumb : TextInputLayout should wrap TextInputEditText instead of the normal EditText.

What is contentDescription Android studio?

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 . A content label sometimes depends on information only available at runtime, or the meaning of a View might change over time.


2 Answers

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


like image 135
ArnaudR Avatar answered Oct 16 '22 10:10

ArnaudR


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

like image 33
ChrisCM Avatar answered Oct 16 '22 11:10

ChrisCM