-
Notifications
You must be signed in to change notification settings - Fork 84
Grouping non-focusable content with android:focusable
shouldn't be recommended
#4
Comments
Seems like this might be a solution to issue #1 |
I have been encountering this exact issue in my development work. |
Excellent article. I just spent a few days doing my first accessibility rework and finding the same issues of grouping content but allowing keyboard navigation. You've encapsulated the issues well. |
from Android P onwards, you can use android:screenReaderFocusable to achieve accessibility focusable, cheers~~ |
Hi there - this codelab has been recently updated. Closing out this issue as it's over a year old; please comment if you are still running into this problem. Thank you! |
@tiembo The codelab still says to use |
The issue still exists because we need to set the view as focusable=true, in order for it to be read by talkback. Then the keyboard focus will also go there, which is not required. How do we solve this for Android Versions < P ? |
How would you remove the focus for a webview while using Talkback? |
|
The project linked from that bug seems to be missing |
First of all, I appreciate all the work Google is putting together about accessibility. It's great to have more materials about Android Accessibility.
I'm an accessibility professional myself that have been working closely with Android applications. I'd like to share a few thoughts/problems about the subject of grouping content.
Focus navigation vs Accessibility Focus
Here's a quick definition before we continue:
Focus navigation: Similar to desktop keyboard navigation (tab, arrows keys, enter, esc). Keyboard or Directional Pad users. Focus is placed only on items that require user interaction (e.g. clickable views or buttons, inputs like
EditText
,CheckBox
,Switch
, etc).Accessibility Focus: Focus for accessibility services, primarily screen readers such as TalkBack. Focus is placed on all meaningful views of the screen, including non-focusable views such as
TextView
orImageView
, which has either text or content descriptions.The problem
Google has been advocating a technique to group non-focusable items by using
android:focusable="true"
to the parentViewGroup
so that its contents are read all at once for screen reader users.You can see this recommendation in one of the Google Code Labs courses.
While grouping content is good for screen reader users, it creates a problem for keyboard users.
The problem is that
android:focusable
is meant for focus navigation and not accessibility focus. The consequences are:ViewGroup
that only has text views and no actions.Solutions
Unless if the statements above are wrong, then I recommend the following:
Focus behavior in a
ViewGroup
Regardless of the issue mentioned above, there's an interesting thing about allowing a
ViewGroup
to receive focus. Consider the following code:What's the focus behavior for focus navigation (Keyboard)?
LinearLayout
.Button
.This is the expected behavior since we've asked for the
LinearLayout
to receive focus.What's the accessibility focus behavior?
LinearLayout
, announcing all its text content except for theButton
text: "Heading one, Heading Two".Button
, announcing the button: "Action, Button".This creates a problem since the order here matters and the original order is different then the one being announced.
Solutions
There are two ways that developers have been solving this issue:
android:focusable
from the container (no need to group text content if they are separated by focusable views) or...android:focusable
to the twoTextView
inside.Removing
android:focusable
from the container is not always an option and having focus on a container can actually be important. For example, aViewPager
will announce that you are on a multi-page view, which page it is currently displaying, and allowing us to use gestures or keyboard arrows to switch pages. We still want to keep this behavior.ViewPager
is a very popular widget and it is quite common to find this problem on many Android apps.Adding
android:focusable
to the twoTextView
is a solution but it makes non-focusable views now focusable to keyboard users (the issue mentioned at the beginning). ForViewPager
, developers must also provide at least anandroid:contentDescription
to theViewPager
, otherwise the it won't gain focus since it has no description.Adding
android:importantForAccessibility="yes"
to the twoTextView
doesn't help since they are already set toyes
by default. What dictates the accessibility focus behavior here is wether child views is focusable or not.Luckily, we can set a view focusable only to accessibility services. To do this, we have to set to
true
the setFocusable(boolean focusable) method in the AccessibilityNodeInfo using an accessibility delegate instead of the setFocusable(boolean focusable) from a View.It would be better, though, if Android could provide something like
android:accessibilityFocusable
. There could be other options like changing TalkBack behavior or fixing the most popularViewGroup
s likeViewPager
,RecyclerView
, etc.I'm looking for a feedback on this, see if any of my suggestions or assumptions are wrong, or even the possibility of Google to implement any of the suggestions.
Thanks!
The text was updated successfully, but these errors were encountered: