Change text spoken using Talkback in Android

I am trying to change the text declared by TalkBack when the ImageView is targeting accessibility.

Android documentation says we have to create AccessibilityDelegate and override onPopulateAccessibilityEvent (I am using the support library because I also support GingerBread)

So my code looks like this:

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 in my view, the delegate is set, but the modified text is not readable. It just reads the original content description. Am I doing something wrong or am I missing something about the accessibility features?

While executing the code, it appears that it is adding the correct text, but nevertheless no changes in the spoken text.

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

+3


source to share


1 answer


In ICS and above, TalkBack does not use the availability event text in most cases. Instead, it checks the text and description of the content of the AccessibilityNodeInfo displayed in the view. You will need to override onInitializeAccessibilityNodeInfo.

In most cases, you just need to call View.setContentDescription.



In this particular case, you don't have to install anything as TalkBack handles types and type manipulation. We strongly advise developers not to add descriptions such as "button" or "image."

+6


source







All Articles