简体   繁体   中英

Android TalkBack keep highlighted position on Screen Rotation

Use case:

  1. Enable the Google TalkBack accessibility service and navigate to an app (eg Google Messenger )
  2. In this app, assuming that you'll be presented with a list of items to select, arbitrarily navigate to one of them using Talkback gestures ( swipe right or just click once on one of them)
  3. Rotate the screen

Expected behaviour:

  • The previously highlighted item should still be highlighted; the user should be able to continue it's navigation
  • The Google Messenger app is a perfect example of this correct behaviour

Messenger After rotation

My Sunshine app behaviour:

  • The previously highlighted item is not highlighted after Screen Rotation
  • The user has to navigate again to the previously selected item
  • Depending on the screen, finding and having an item selected again can be a pain... not what we want to induce to our user

Sunshine After rotation

How should we implement this? I'm thinking, as a solution, at Accessibility Events and intercepting them... but this doesn't seem to be right, doesn't seem to be "best practice" (eg creating a Custom View and implement the methods handling these Events)

! Note that the green highlighted list item doesn't seem to be focused ( getCurrentFocused() returns null )

! Note that the list items become focused if we use D-Pad navigation, instead of TalkBack navigation (but this is another discussion...)


LE:

  • I've spend a whole day on this, trying to "get the focus" of the highlighted item, but the item is NOT focused . This is why I assume that this feature must be tackled in some other way and I would like to know your ( ! ) experienced opinion before I spend another 2 days re-creating all the used Android components (as I assume it could be done - this doesn't sound very "best practice", doesn't it ? )
  • This is NOT a homework , there's nothing wrong with my current code (so, there's no code to post, unless one would like my whole project) and, given that this is my first post, I could not attach more than 2 pictures (this is why the "before" screens are missing)
  • Just give me a good hint, based on experience, and I will implement it and post the finished, working code here.

It should work out of the box if you implement stable IDs in your RecyclerView.Adapter (and potentially disable the ItemAnimator on the RecyclerView ( rv.setItemAnimator(null) ) which you can do conditionally if TalkBack is enabled).

Here's a blog post I wrote about the item animator bug .

I ran into the same problem while working on the same project.

Hint: listView.setItemChecked(int position, boolean value);

Good luck :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM