如何停止将辅助功能宣布为“ button”? [英] How to stop Accessibility from announcing android button as "button"?

查看:129
本文介绍了如何停止将辅助功能宣布为“ button”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android中有一个按钮,上面写有文本下一步
时,我将可访问性光标放在按钮上,它读出下一个按钮。这是我不想要的东西。我想在任何时候将光标放在下一步按钮上,它都必须读出为下一步按钮。双击以选择。通过设置
btn.contentDescription(下一步按钮。双击以选择)
,我可以轻松地做到这一点,但是它会读出如
下一个按钮。双击以选择按钮 ,表示它还读出了最后一个按钮,看起来很奇怪,带有 button文本得到两次阅读。

I have a button in Android which has text "Next" written on it. when, I have the accsessibility cursor focus on the button, it reads out "Next button". This is something I don't want. I want whenever, the cursor to have focus on the "Next" button, it must read out as "Next button. Double tap to select". This I can easily do, by setting the btn.contentDescription("Next button. Double tap to select"), but then it reads out as "Next button. Double tap to select button", means it additionally reads out the last button, which seems very odd, with the "button" text getting read twice.

有什么办法可以停止最后一个要宣布的按钮?

Is there any way, by which I can stop the last button to be announced?

推荐答案

我知道我来晚了,但是在这里为所有可能碰到这篇文章的人发布答案。

I know I'm way late to the game, but posting an answer here for anyone that may happen to come across this post.

其他是正确的...我们不应在内容描述中放置小部件的类型或如何与小部件进行交互。但是,一切并不会丢失。

The others are right... we should not be putting the type of widget or how to interact with the widget in the content description. However, all is not lost.

从API 21开始,有一种方法可以通过AccessibilityNodeInfo自定义交互文本。您可以通过两种不同的方式使用此类:

Starting with API 21, there is a way to customize the interaction text through AccessibilityNodeInfo. You can use this class in two different ways:

AccessibilityNodeInfo具有 getActionList()方法。您可以通过向该列表添加新项来添加自定义TalkBack读出的文本:

AccessibilityNodeInfo has a getActionList() method. You can add customize the text that is read out by TalkBack by adding a new item to that list:


info.getActionList().add(new AccessibilityNodeInfo.AccessibilityAction(AccessibilityAction.ACTION_CLICK, "select");


上面的代码应将双击以激活 更改为双击以选择 。我说应该,因为我只是从内存中编写该代码...我尚未验证它是否100%正确,但是应该是符合这些原则的。

The above code should change "Double-tap to activate" to "Double-tap to select". I say should because I'm just writing that code from memory... I haven't verified it's 100% correct, but it should be something along those lines.

利用该类有两种方法,您选择的一种将取决于您的情况。

There are two ways to utilize that class, and the one you choose is going to depend on your situation.

方法1:将视图子类化:

如果创建正在使用的视图的子类(对于OP,它将是Button的子类),则可以覆盖 onInitializeAccessibilityNodeInfo()方法并将代码放在此处
文档: https://developer.android.com/reference/android/view/ View.html#onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)

If you create a subclass of the view you are using (in the case of the OP it would be a subclass of Button) then you can override the onInitializeAccessibilityNodeInfo() method and put the code there. Documentation: https://developer.android.com/reference/android/view/View.html#onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)

方法2:创建视图可访问性委托

这可能会更加棘手和复杂,但确实提供了很大的灵活性,因为您不必将正在使用的视图子类化。

This can be a bit more tricky and involved, but it does offer a ton of flexibility because you don't have to subclass the views you are working with.

每个视图都有一个方法,可让您设置一个可访问性委托,其作用类似于中间人,您可以在信息进入话语提示之前进行调整,以实现可访问性

Every view has a method that allows you to set an accessibility delegate, which acts like a man-in-the-middle and you can tweak things for accessibility purposes before the info goes to TalkBack.

文档: https://developer.an droid.com/reference/android/view/View.html#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)

因此,基本上,您创建了View.AccessibilityDelegate和使用上面发布的代码覆盖它的 onInitializeAccessibilityNodeInfo()方法。

So basically you create a subclass of View.AccessibilityDelegate and override it's onInitializeAccessibilityNodeInfo() method with the code I posted above.

文档: https ://developer.android.com/reference/android/view/View.AccessibilityDelegate.html#onInitializeAccessibilityNodeInfo(android.view.View,%20android.view.accessibility.AccessibilityNodeInfo)

最后但并非最不重要...

我确实遇到了阻止 Double点按即可激活 文本,使其不会被话语提示说出来。 仅在确实删除它时才应使用。

I did come across a way to stop the "Double tap to activate" text from being spoken out by Talkback. This should only be used when it really does make sense to remove it.

我重复...

我最近遇到了一个有意义的案例。我使用的是TabLayout,但我注意到,当焦点位于所选选项卡上时,话语提示将始终读出双击选择(是的,我已经使用上述方法更改了文本)。好吧...我们不想告诉用户选择一个已经选择的标签,尤其是当操作导致无操作时。因此,我使用了这个小技巧来摆脱它,但仅限于当前选择的选项卡。我只留下了未选中的标签,这样话语提示仍会为他们提供交互文本。

I did recently come across a case where it made sense. I was using a TabLayout, and I noticed that Talkback would always read out "Double-tap to select" when the focus was on the selected tab (yes, I had used the method described above to change the text). Well... we don't want to tell the user to select a tab that is already selected, especially when the action results in a no-op. So, I used this little trick to get rid of that, but only for the currently selected tab. I left the unselected tabs alone so that Talkback would still give them the interaction text.

在您的 onInitializeAccessibilityNodeInfo()中方法,您可以将以下代码删除以删除该文本:

In your onInitializeAccessibilityNodeInfo() method, you can put the following code to remove that text:

info.addAction(AccessibilityNodeInfo.ACTION_FOCUS);

同样,我是从内存中编写此代码的,所以我不知道如果那是100%,但是它为您提供了要做的要点。

Again, I'm writing this code from memory, so I don't know if that's 100% there, but it gives you the gist of what to do.

这篇关于如何停止将辅助功能宣布为“ button”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆