I have a form with accessibility. When the user clicks on the button at the bottom of the form and there is an invalid EditText field (e.g. it is empty), I would like the error to be announced and for the view to scroll to that EditText field. I have attempted several methods, but I encounter the issue that when I scroll to that part of the form, Talkback drags the focus with the scrolling and announces the last view.
Here is what I have tried:
XML:
android:importantForAccessibility="yes"
android:accessibilityLiveRegion="assertive"
Programmatically:
field.requestFocus()
field.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
//scrollView.smoothScrollTo(0, field.bottom) - older try
I have also tried to clear the focus from other views (which didn't work), disable Talkback before scrolling and enable it after (which I couldn't), and scroll to the point that the field is at the bottom of the screen so that Talkback will announce it (if the field is at the top of the screen, you can't scroll there). How does it work in your apps?
This is a simple answer with many implications - I'm separating the two so you can decide how much depth you'd like to go into.
EditText
// automatically gets announced by screen reader and has a built in image
view.error = "Descriptive error"
LiveRegion
:<!-- every time the text property is changed it will be announced by TalkBack -->
<!-- You will need to add your own styling and remember you can only give one -->
<!-- element of feedback at a time -->
<TextView
android:id="@+id/error"
android:accessibilityLiveRegion="assertive"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Changing the setting of any user interface component does not automatically cause a change of context unless the user has been advised of the behavior before using the component.
A change of context being defined as such:
Changes in context include changes of:
- user agent;
- viewport;
- focus;
- content that changes the meaning of the Web page
There may be times where we have to adjust focus because the system is consistently behaving strangely (normally because we're loading components in a strange way - e.g. dynamically from some web call - but even here careful consideration should be taken)
LiveRegions
) - inform the user, but let the user navigate to where they need to fix any errors. Remember that there are many assistive technologies other than Screen Readers - Magnification, Switch Access, Voice Access, etc.Test your app with TalkBack - when you turn it on for the first time there is a tutorial. I have also made a cheat sheet to help you and I have made a desktop tool and an Android Studio plugin for checking different accessibility aspects on Android.
Less is more, as long as you remember: Consistency (standard API's), Configurability (Giving users multiple means) and Consent (give the user the choice)
Test your app with real users. There is a great company called Fable that do accessibility testing of apps with users who have different disabilities. This is the best feedback you can get.
Just check your styles in dark and light mode.