1

I have drawn the Swipe to delete button(RectF) in Recycle view with the help on

 val oBackground = RectF(itemView.right.toFloat() - buttonWidth, itemView.top.toFloat(), itemView.right.toFloat(), itemView.bottom.toFloat())
    paint.color = ContextCompat.getColor(viewHolder.itemView.context, R.color.color_cc0013)
    canvas.drawRect(optionsBackground, paint)

    // Displays delete drawable within specified bounds
    val deleteBtmp: Bitmap = getBitmapFromVectorDrawable(viewHolder.itemView.context, R.drawable.vector_delete)
    val destination = RectF(
        itemView.right.toFloat() - buttonWidth + paddingLeft,
        itemView.top.toFloat() + paddingTop,
        itemView.right.toFloat() - paddingRight,
        itemView.bottom.toFloat() - paddingBottom
    )
    canvas.drawBitmap(deleteBtmp, null, destination, paint)

How I can set TalkBack accessibility focus on swipe to delete button(deleteBtmp) in Recycleview ?

enter image description here

Gurmeet Singh
  • 199
  • 10

1 Answers1

0

Your delete button is what we call a "virtual view". You'll need to expose it with an AccessibilityNodeProvider.

ExploreByTouchHelper is a wrapper intended to simplify the process.

Much simpler, however, would be to adjust your UI to use a regular button, and take advantage of the built-in accessibility reporting.

Phil Weaver
  • 738
  • 3
  • 7
  • Thanks, @Phil Weaver for showing interest. As per my understanding, ExploreByTouchHelper is working with customer views. But In my case, I have drawn a RecF on the canvas when the user performs swipe left action on any item. Please guide me how I can use ExploreByTouchHelper or AccessibilityNodeProvider in that case. Please share any sample if you have – Gurmeet Singh Mar 09 '21 at 11:29
  • Drawing a button on the canvas is pretty much what we mean by a custom view. This feels similar to RadialTimePickerView: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/RadialTimePickerView.java#1070 – Phil Weaver Mar 10 '21 at 18:04