Skip to content Skip to sidebar Skip to footer

Android Talkback: Hint Overwrites Contentdescription

I have an EditText like below

Solution 1:

What you want to do is use LabelFor instead. LabelFor allows a visual label to be associated with an EditText box. You can make the visual label invisible if you'd like, so that it doesn't change your visual layout.

The down side to hints, is that they disappear after text is entered, making them pretty poor accessibility tools. If you're relying on hints for your Accessibility information, your app is not accessible.

Do something like this:

<TextViewandroid:text="@string/yourEditTextDescription"android:labelFor="@+id/editTextField" /><EditTextandroid:id="@+id/editTextField"/>

Solution 2:

According to the official documentation, you shouldn't be setting android:contentDescription equal to anything. Instead, only use android:hint.

<EditText
    android:id="@+id/extUsername"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:hint="Username" />

"field" from your contentDescription should be removed, because TalkBack will announce it as "Username edit box"

Solution 3:

Unfortunately, android:hint will always override android:contentDescription. You can create TextView which you will use only to set android:labelFor but from my experience TalkBack will then read both hint and labelFor.

The right way to add TextView which is only for labeling EditText for TalkBack :

<TextViewandroid:layout_width="0dp"android:layout_height="0dp"android:text="@string/yourDescription"android:labelFor="@+id/editText" /><EditTextandroid:id="@+id/editText"/>

So one of the solutions is that you can check to see if TalkBack is on and change hint programmatically. You can check if TalkBack is on with:

if(context.isScreenReaderOn){
    ...
}

And you create an inline function in Kotlin like :

fun Context.isScreenReaderOn():Boolean{
    val am = getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
    if (am != null && am.isEnabled) {
        val serviceInfoList =
            am.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN)
        if (!serviceInfoList.isEmpty())
            returntrue
    }
    returnfalse}

Solution 4:

Note: For EditText fields, provide an android:hint attribute instead of a content description, to help users understand what content is expected when the text field is empty. When the field is filled, TalkBack reads the entered content from content description to help user, instead of the hint text.

For Hint -> android:hint

For TalkBack -> android:contentdescription

Solution 5:

You should extend EditText class with overriden TextView.getTextForAccessibility() method to get expected behaviour in the following way:

public CharSequence getTextForAccessibility() {
    CharSequence text = getText();
    if (TextUtils.isEmpty(text)) {
        text = getContentDescription();
    }
    return text;
}

Post a Comment for "Android Talkback: Hint Overwrites Contentdescription"