Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing text spoken by talkback in Android

I am trying to change the text announced by TalkBack when an ImageView is focused through accessibility.

The Android documentation states that we should create an AccessibilityDelegate, and override onPopulateAccessibilityEvent (I am using the support library because I am also supporting GingerBread)

Thus, my code is the following:

public static void setImageDelegate(View view) {
    AccessibilityDelegateCompat delegate = new AccessibilityDelegateCompat() {
        @Override
        public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
            event.getText().add(event.getContentDescription() + ", image");
        }
    };
    ViewCompat.setAccessibilityDelegate(view, delegate);
}

When I call this function on my imageview, the delegate gets set, but the modified text is not being read. It simply reads the original content description. Am I doing something wrong or missing something about the accessibility functions?

Stepping through the code, it seems to be adding the correct text, but still, no change in spoken text.

Note: the above is a contrived example, content description could be used, but I'm trying to figure out why it doesn't work before I try it on custom views.

like image 904
Allen Z. Avatar asked Sep 19 '14 18:09

Allen Z.


People also ask

How do I change the voice on my TalkBack Android?

If you have already enabled TalkBack or Select to Speak you will see a small Play button next to each voice. Tap the Play button to hear a sample, or tap the button next to the voice to use it.

What is TalkBack settings?

TalkBack is the Google screen reader included on Android devices. TalkBack gives you eyes-free control of your device. The setup of your device depends on the device manufacturer, Android version, and TalkBack version. These help pages apply to most devices, but you might experience some differences.


1 Answers

In ICS and above, TalkBack doesn't use the accessibility event text in most cases. Instead, it checks the text and content description of the AccessibilityNodeInfo exposed by the view. You would need to override onInitializeAccessibilityNodeInfo.

In most cases, though, you would just want to call View.setContentDescription.

In this particular case, you shouldn't set anything since TalkBack handles speaking control types and capabilities. We strongly advise developers against adding descriptions like "button" or "image."

like image 180
alanv Avatar answered Nov 03 '22 01:11

alanv