I am new with android accessibility - TalkBack
.
I am aware of basic things like contentDescription
, importantForAaccessibility
and how they make node tree, etc.
In my problem, I want to shift accessibility focus on RecyclerView
's first element on some action.
Usually someView.requestFocus()
or someView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
works.
But it seems to not working as expected in RecyclerView
.
I have tried to solve it by:
android:accessibilityLiveRegion="polite"
but it only announce that list is there. But it doesn't go on an element with accessibility focus.
By focusing the first element from the adapter - but it's a bad idea to do so!
Other than that, android:accessibilityTraversalAfter
and android:accessibilityTraversalBefore
also don't work well with a list view in android.
someView.requestFocus()
someView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
The main activity layout file with RecyclerView, activity_main.xml The layout file for list item in the recyclerview, the focusable has to set to true, and the background is set to a selector drawable. list_item.xml The background selector drawable, this will make the focused list item to display black background. item_selector.xml
There are 2 ways by which you can do. 1: When you are creating any LayoutManager for the RecyclerView, Make the last parameter in its constructor as true. LinearLayoutManager layoutManager = new LinearLayoutManager (MainActivity.this,LinearLayoutManager.HORIZONTAL,true); 2: Simply tell the RecyclerView to scroll to the last position.
where the user makes a selection. Once the user makes a selection and the presented is dismissed, the accessibility focus (SHOULD?) be selected at tableview cell index 3, but instead the focus is set back to the initial element in the view, in my case most top-left element.
I usually call scrollToPosition when the dataset is succesfully inserted to a RecyclerView, for example: This way, we don't have to wait certain millisecond to scroll a ReyclerView. When there is a new dataset, we can trigger scrollToPosition or smoothScrollToPosition and be sure RecyclerView is scrolled.
RecyclerView's getChildAt()
method worked for me.
recyclerView.getChildAt(0).requestFocus()
recyclerView.getChildAt(0).sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
Request Focus with Specific ViewId
and gets the first element of that node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With