Android TalkBack: Hint overwrites contentDescription

android talkback programmatically
android set content description programmatically
android talkback focus order
android check if talkback is enabled
android talkback tutorial
android talkback edittext

I have an EditText like below

    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.

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:

     android:labelFor="@+id/editTextField" />

<EditText android:id="@+id/editTextField"/>

Content labels - Android Accessibility Help, To override this behavior and indicate that you want to provide your own For EditTexts or editable TextViews , use an android:hint attribute to indicate the An android:contentDescription should not be used as a content label for editable Views . If TalkBack moves focus to some element, but doesn't speak a meaningful  Seem Google just added the setContentDescription(CharSequence contentDescription) method to the MenuItem class on API 26 (Android O). Updated: Thanks for new @tim.paetz answer . Look like all versions are now supported setContentDescription for menu item using android support v4 libraries.

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

    android:hint="Username" />

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

Customising usage hints for Android TalkBack, TalkBack offers a set of usage hints which are read aloud on actionable Views. these as available actions after reading the View's content description. @​Override public void onInitializeAccessibilityNodeInfo(View host,  android:hint. 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:labelFor. Use an android:labelFor attribute to indicate that a View should act as a content label for another View.

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 :

         android:labelFor="@+id/editText" />

    <EditText android: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:


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 =
        if (!serviceInfoList.isEmpty())
            return true
    return false}

Principles for improving app accessibility, Screen readers such as TalkBack can announce these labels to Although you usually add labels using the contentDescription In these situations, you can use the android:hint attribute, as shown in the following snippet: <! override fun onBindViewHolder(holder: MyRatingViewHolder, position: Int) { Questions tagged [talkback] Android TalkBack: Hint overwrites contentDescription correct data to the accessibility framework by giving android

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;

Android developer guide, The contentDescription attribute must also be used on custom elements to indicate their nature. @Override protected void onCreate(Bundle savedInstanceState) { super. It is common to check the Android version before triggering TalkBack vocalization. Can be used in the xml android:hint or programmatically setHint . Follow this link for solution: Android Lint contentDescription warning. Resolved this warning by setting attribute android:contentDescription for my ImageView. android:contentDescription="@string/desc" Android Lint support in ADT 16 throws this warning to ensure that image widgets provide a contentDescription

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

accessibility, The four main accessibility properties for Android controls are hint, contentDescription, focusable and labelFor. While all of these properties can be specified for  Make apps more accessible Android apps should aim to be usable by everyone, including people with accessibility needs. People with impaired vision, color blindness, impaired hearing, impaired dexterity, cognitive disabilities, and many other disabilities use Android devices to complete tasks in their day-to-day lives.

Android Accessibility Properties and TalkBack, For this reason, set the android:contentDescription attribute for every When the field is filled, TalkBack reads the entered content to the user, instead of the hint text. In these situations, you can provide explicit overrides to the ordering using​  Edit box. " TalkBack knows to announce "Enter favorite song" because the EditText has an android:hint attribute that is set to "Enter favorite song" in the layout XML. Hint: It is a best practice to use android:hint instead of contentDescription on EditTexts. Swipe right to focus on the Go button.

Making Applications Accessible, In this Android accessibility tutorial, learn how to make apps that To turn on TalkBack, go to Settings on your Android device. the description of what was found to be wrong, and a suggestion for how to fix it. You can easily improve this user experience by adding a android:contentDescription attribute  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 to the user, instead of the hint text. Enabling Focus Navigation

Android Accessibility Tutorial: Getting Started, To turn on TalkBack, go to Settings on your Android device. Then find Accessibility/TalkBack, and toggle the tool on.. With the default settings, in a left to right language, swipe right to advance to the next item on the screen, left to go to the previous, and double tap to select.

  • Don't set content descriptions on edit fields. Don't include component type in content descriptions. The accessibility service handles this, if needed. Just set the android:hint or use android:labelFor if you have a separate label.
  • I got the error in xml file. TextView needs android:layout_width and android_height error message shown. How can i handle it.
  • Add android:layout_width and android:layout_height? I removed scaffolding to demo just the important bits for accessibility. Your xml still needs to include all of those other styling bits that Android usually expects.
  • I tried with all the styling bits usually we use in the xml file. But i got the error mesage castException: android.widget.TextView cannot be cast to android.widget.EditText
  • It sounds like your trying to cast a TextView to an EditText... You should add your Java and your xml to a different question. Your current problem is unrelated to this. And extended debugging conversations in comments are bad.
  • It seems that if you make the TextView's visibility either invisible or gone, TalkBack doesn't read this label when you tap on the EditText.
  • This method appears in TextView's source code, but is not reported here and I cannot override it.
  • That's a private method, you can't override it.
  • Hints should not contain important information, like the name of the field. Username is very important information, and should be more than temporary. A TalkBack user shouldn't have to delete their entered text, to know what it is they entered the text for. A bad hint: Username. A good hint: John.Smith.
  • This is not the answer. Strings are already in string.xml file. I wrote it like that to make it easy to read for you.