Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TalkBack: Hint overwrites contentDescription

I have an EditText like below

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

I want TalkBack to say "Username field" but it says "Username". It ignores contentDescription.

Do not tell me to remove hint or contentDescription. I need to use both.

Any advices will be appreciated.

like image 916
Egemen Hamutçu Avatar asked Apr 27 '15 07:04

Egemen Hamutçu


People also ask

What does Android contentDescription do?

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.

How do I use TalkBack on Android?

Getting Started. Enabling TalkBack: Go to Settings > Accessibility > TalkBack to turn on TalkBack. To activate the TalkBack shortcut, go to Settings > Accessibility and turn on the Volume Key Shortcut. You can then hold the volume keys for a few seconds to turn TalkBack on or off.

What is label in Android?

Editable items in an app allow users to enter text. Each editable item should have a descriptive label stating its purpose. Android offers several ways for developers to label Views in an app's user interface. For editable items in an interface, some of these ways of labeling can improve accessibility.

How do I know if TalkBack is enabled Android?

More details: if you are strictly interested in whether TalkBack is enabled, use am. isTouchExplorationEnabled() . (If Select to Speak is enabled and TalkBack disabled, am. isEnabled() will still return true.)


2 Answers

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:

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

<EditText android:id="@+id/editTextField"/>
like image 92
ChrisCM Avatar answered Oct 05 '22 00:10

ChrisCM


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"

like image 38
Shalbert Avatar answered Oct 05 '22 01:10

Shalbert