简体   繁体   中英

Android - Talkback announces class type at end of content description.

This is happening in several places for multiple class types but I'll stick with a button example for now.

So I have a button which I want talkback to announce as "Play". The content description is set to "Play". However, talkback is also announcing the class too, so it reads as "Play Button".

I tried a solution I found elsewhere by overloading the onInitializeAccessibilityNodeInfo method

private void setupContentDescriptors() {
    mPlayPauseButton.setAccessibilityDelegate(new View.AccessibilityDelegate() {
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info)
        {
            super.onInitializeAccessibilityNodeInfo(host, info);

            //blanked to prevent talkback from announcing class/type
            info.setClassName("");
            info.setContentDescription("Play");
        }
    });
}

Setting the class name to "" worked perfectly, but I soon found out this solution only worked for API 23 and above. According to the docs, "Starting in API 23, delegate methods are called after host methods, which all properties to be modified without being overwritten by the host class."

I've tried several other methods to no avail. Ideas?

Prior to API 23, you will need to create a subclass and implement onInitializeAccessibilityNodeInfo() if you need to override the class name. You cannot override it by using a delegate.

That said, TalkBack is attempting to provide a consistent and high-quality experience for your user by speaking role descriptions. In the vast majority of cases, you should not attempt to override this behavior.

If you have a small and well-known user circle, maybe this is another alternative to the answer of alanv.

In Talkback 5.2.1(*) you can do this:

Under "Settings -> Accessibility -> Talkback -> Settings -> Verbosity

There you can switch on / off the entry "Speak element type" .

With this the user itself can decide if he wants to hear the element type or not. This is another argument NOT to tinker with the way Talkback reads elements.


(*) I did not find any documentation about when the verbosity-setting for speaking elements was introduced. On my Android devices with Talkback 5.2.1 it's working, while devices with Talkback 5.0.3 dont have this setting. So anywhere in between it had to be introduced.

have you tried

ViewCompat.setAccessibilityDelegate(mPlayPauseButton, new 
AccessibilityDelegateCompat() {
    @Override
   public void onInitializeAccessibilityNodeInfo(View host, 
       AccessibilityNodeInfoCompat info) {
       super.onInitializeAccessibilityNodeInfo(host, info);
       info.setClassName(null);
       info.setContentDescription("your label");
   }
})

ViewCompat should take care of the version handling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM