简体   繁体   English

Android TalkBack 和片段堆栈

[英]Android TalkBack and fragment stack

For an application that I work on, I need to implement accessibility.对于我正在处理的应用程序,我需要实现可访问性。 Everything works fine except for one screen where I have to fragments added to my activity.一切正常,除了一个屏幕,我必须将片段添加到我的活动中。 Basically, the fragment that is above is a dial keyboard to enter a passcode.基本上,上面的片段是用于输入密码的拨号键盘。 This fragment is added with a fragmentTransaction.这个片段被添加了一个片段事务。

The thing is that the talkback focus is set on the elements of the underneath fragment.问题是对讲焦点设置在下面片段的元素上。

Do you know if there is a way to set the talkback focus on the dial fragment?你知道是否有办法在拨号片段上设置对讲焦点? I just want to "disable" the fragment underneath to get focus我只想“禁用”下面的片段以获得焦点

Thanks,谢谢,

UPDATE更新

I figured out the solution.我想出了解决办法。 you can disable the accessibility of the first fragment before you do the fragment transaction.您可以在执行片段事务之前禁用第一个片段的可访问性。

rootView = inflater.inflate(R.layout.first_fragment, null, false);

rootView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);

and now you commit your fragment transaction.现在你提交你的片段交易。 Second fragment won't leak the focus to first fragment.第二个片段不会将焦点泄漏到第一个片段。

Don't forget to enable the accessibility of first fragment in case you're coming back to the first fragment.不要忘记启用第一个片段的可访问性,以防您回到第一个片段。

if(rootView != null) {
    rootView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
}

Are you using fragmentTransaction.add?你在使用 fragmentTransaction.add 吗?

If so you sould use fragmentTransaction.replace!如果是这样,您应该使用 fragmentTransaction.replace!

Add function also did problems with clicking the below fragment views.单击下面的片段视图时,添加功能也有问题。

So please, use replace.所以请使用替换。

Your problem isn't "sending" focus to the correct place.你的问题不是“发送”焦点到正确的地方。 Forcing focus around to different places is generally a bad idea, and inaccessible.强制将注意力转移到不同的地方通常是一个坏主意,而且无法访问。 Your problem is that you have elements on the screen that aren't visible, but are being focused by TalkBack.您的问题是屏幕上的元素不可见,但被 TalkBack 聚焦。 What you want to do is hide these elements from TalkBack.您要做的是在 TalkBack 中隐藏这些元素。 Actually, you probably want to remove them completely, but let's assume that they need to be on the screen.实际上,您可能想要完全删除它们,但让我们假设它们需要出现在屏幕上。 What you can do is hide them from the accessibility service:您可以做的是将它们从无障碍服务中隐藏起来:

rootViewOfFragment.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);

This will hide those views from TalkBack.这将从 TalkBack 中隐藏这些视图。 This is a better solution than forcing focus to a specific element, as this is generally an accessibility violation under WCag 2.0.这是比强制关注特定元素更好的解决方案,因为这通常是 WCag 2.0 下的可访问性违规。 Though if the elements on screen are not completely hidden by your "top" fragment, this is also a violation, and you should actually just leave things be.尽管如果屏幕上的元素没有被您的“顶部”片段完全隐藏,这也是一种违规行为,您实际上应该保持原样。

Maybe you can call requestAccessibilityFocus() when the second fragment resumes也许您可以在第二个片段恢复时调用 requestAccessibilityFocus()

@Override
public void onResume() {
    super.onResume();
    yourView.requestAccessibilityFocus();
}

Adding添加

view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);`
view.performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);

inside onResumeonResume里面

and adding并添加

view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);

inside onPause works for me.onPause里面对我onPause

Using replace fragment over add fragment is IMO a best answer, see here使用替换片段而不是添加片段是 IMO 的最佳答案,请参见此处

https://stackoverflow.com/a/21684520/3540391 https://stackoverflow.com/a/21684520/3540391

Look at method View.查看方法视图。 sendAccessibilityEvent (AccessibilityEvent.TYPE_VIEW_FOCUSED). sendAccessibilityEvent (AccessibilityEvent.TYPE_VIEW_FOCUSED)。 sendAccessibilityEvent changes focus from Talkback. sendAccessibilityEvent将焦点从 Talkback 更改。 I don't know much about Talkback, pls read a link on SO @ When using TalkBack, what is the preferred way to alert the user when the contents of a TextView have changed?我对 Talkback 不太了解,请阅读 SO @ 上的链接, 当使用 TalkBack 时,当 TextView 的内容发生变化时,提醒用户的首选方式是什么? . .

Good luck...祝你好运...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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