Android accessibility: Talkback says 'out of list' in addition to announcing an ImageView's content description

Viewed 3148

I have an ImageView in the layout with content description = 'Close'. When Talkback is turned on, it says "Close button, out of list". Why does Talkback say 'out of list' in addition and how can I avoid it? P.S. there is also a RecyclerView in the layout, maybe it affects somehow.

2 Answers

When accessibility focus is in a list (like a RecyclerView) it adds "in list" when describing the item, so the user knows where they are. When you move out of the list (say by tapping on your image) it adds "out of list" to say you've moved out of the list.

Generally you don't want to mess with TalkBack's announcements, they're there to help with accessibility, and users are used to hearing standard phrases like that. If you change them it becomes less consistent and potentially confusing.

The exception is adding information, say by adding a description for the action, so instead of "double tap to activate" it says something more useful like "double tap to confirm your choices". There's an example of that here: https://buffer.com/resources/announce-actions/

I was also facing a similar issue and I found a workaround for this. I used accessibility delegation to re-request accessibility focus on the Image button when it gets the accessibility focus. Here is my code:

My layout file looks something like this.

<?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>

I used the following code snipped in my fragment:

   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)
        }
    }

Hopefully, this will work for you too.

Related