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

血红的双手。 提交于 2019-12-10 22:29:02

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/37843919/android-talkback-announces-class-type-at-end-of-content-description

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!