Android 可访问性:除了宣布 ImageView 的内容描述外,Talkback 还说“不在列表中”

问题描述

我在布局中有一个 ImageView,内容描述 = 'Close'。打开 Talkback 后,它会显示关闭按钮,不在列表中”。为什么 Talkback 还会说“不在列表中”,我该如何避免? 附注布局中还有一个 RecyclerView ,也许它有什么影响。

解决方法

当可访问性焦点位于列表中(如 RecyclerView)时,它会在描述项目时添加“列表中”,因此用户知道它们在哪里。当您移出列表时(例如通过点击您的图片),它会添加“不在列表中”,表示您已移出列表。

一般来说,您不想弄乱 TalkBack 的公告,它们是为了帮助提高可访问性,而且用户习惯于听到这样的标准短语。如果您更改它们,它会变得不那么一致并且可能会造成混淆。

例外是添加信息,比如添加操作的描述,因此它不是“双击激活”,而是更有用的内容,例如“双击以确认您的选择”。这里有一个例子: https://buffer.com/resources/announce-actions/

,

我也遇到了类似的问题,我找到了解决方法。当它获得可访问性焦点时,我使用可访问性委托重新请求可访问性焦点在图像按钮上。这是我的代码:

我的布局文件看起来像这样。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageButton
    android:id="@+id/iv_close_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/back_button_text"
    android:paddingHorizontal="20dp"
    android:paddingVertical="20dp"
    android:src="@drawable/ic_back_arrow"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/rv_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/iv_close_button" />
</androidx.constraintlayout.widget.ConstraintLayout>

我在片段中使用了以下代码:

   iv_close_button.accessibilityDelegate = object : View.AccessibilityDelegate() {
        override fun performAccessibilityAction(
            host: View?,action: Int,args: Bundle?
        ): Boolean {
            if (action == AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS) {
                // Sends an accessibility event of accessibility focus type.
                host?.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED)
            }
            return super.performAccessibilityAction(host,action,args)
        }
    }

希望这对你也有用。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...