修改无障碍焦点顺序 [英] Modify accessibility focus order

查看:70
本文介绍了修改无障碍焦点顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改可访问性焦点顺序?例如,如果我并排有 3 个视图,id 分别为 view1、view2 和 view3,当用户从 view1 向右滑动时,是否有一种简单的方法可以使无障碍焦点转到 view3?

Is it possible to change the accessibility focus order? For example, if I have 3 views side by side, with ids view1, view2, and view3, is there a simple way to make the accessibility focus go to view3 when the user swipes right from view1?

这是我尝试过的:

我在线性布局中有以下内容.

I have the following in a linear layout.

<ImageView
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:id="@+id/imageView"
    android:focusable="true"
    android:nextFocusUp="@+id/imageView3"
    android:nextFocusDown="@+id/imageView3"
    android:nextFocusRight="@+id/imageView3"
    android:nextFocusLeft="@+id/imageView3"
    android:nextFocusForward="@+id/imageView3"
    android:src="@drawable/ic_launcher"/>

<ImageView
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:id="@+id/imageView2"
    android:focusable="true"
    android:src="@drawable/ic_launcher"/>

<ImageView
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:id="@+id/imageView3"
    android:focusable="true"
    android:nextFocusUp="@+id/imageView2"
    android:nextFocusDown="@+id/imageView2"
    android:nextFocusRight="@+id/imageView2"
    android:nextFocusLeft="@+id/imageView2"
    android:nextFocusForward="@+id/imageView2"
    android:src="@drawable/ic_launcher"/>

然后,我启动它并将可访问性重点放在第一个 imageView 上.向右滑动移动到下一个项目时,我希望它将可访问性焦点移动到 imageView3,但它转到 imageView2.

Then, I launch this and place accessibility focus on the first imageView. Upon swiping right to move to the next item, I expect it to move accessibility focus to imageView3, but instead it goes to imageView2.

推荐答案

对于 minSdkVersion >= 22 的应用程序,您可以使用 android:accessibilityTraversalAfter 直接在 XML 中设置屏幕阅读器的遍历顺序:

For applications with minSdkVersion >= 22, you may set the traversal order for screen readers direct in the XML with android:accessibilityTraversalAfter:

<ImageView
    android:id="@+id/imageView"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="30dp"
    android:accessibilityTraversalAfter="@id/imageView3"
    android:layout_height="30dp"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView3"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:src="@drawable/ic_launcher" />

对于支持较低 API 级别的应用程序,可以使用 ViewCompat 以编程方式设置遍历顺序:

For applications supporting lower API levels, the traversal order may be set programmatically with ViewCompat:

ViewCompat.setAccessibilityDelegate(imageView2, object : AccessibilityDelegateCompat() {
    override fun onInitializeAccessibilityNodeInfo(host: View?, info: AccessibilityNodeInfoCompat?) {
        info?.setTraversalAfter(imageView3)
        super.onInitializeAccessibilityNodeInfo(host, info)
    }
})

请记住,屏幕阅读器用户依赖于导航的一致性,因此,更改焦点顺序是一种反模式,应避免.

Please keep in mind that screen reader users rely on the consistency of the navigation, therefore, changing the focus order is an anti-pattern and should be avoided.

这篇关于修改无障碍焦点顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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