Accessibility is enabling users with impared vision , color blindness and many other disabilities to use android devices in their day to day life.
Our app should be accessible by talkBack feature to read out the contents to the user.
How to provide accessibility ?
By adding content description to each view we can provide the accessibility applications some description to notify the users.
<ImageView
...
android:contentDescription="@string/inspect" />
When the accessibility talk back application is pointed to this view, it will speak out the given description to the user. Users can identify or do actions based on the view.
Points to remember while adding descriptions
- Don’t include the UI element type in the description.
- Description should be unique.
- To exclude the UI element from accessibility, set the description to “@null”.
Principles for improving app accessibility
- Labels
Providing labels to UI elements will let users know the meaning and purpose of that particular element. Screen readers such as talk back can announce these labels to users who rely on these services.
This is similar to providing contentDescription for each UI element. - Editable element
For editable elements like editText we can provide “hint” to the element. Which can be an example of what the input is expected. - Grouping contents
UI elements can be grouped to a single element by providing description to the root of the group.
<LinearLayout
…
android:contentDescription=”This is the group description”>
...
</>
Testing :
Manual testing :
To test your app accessibility services enable talk back in your device and interact with the app to experience the accessibility feature
To turn on talk back : Go to settings -> accessibility -> talkback -> turn on/off
Testing with tools :
- Accessibility scanner :
The accessibility scanner app scans your screen and provides suggestions to improve the accessibility of your app. - Pre-launch report in google play :
Once the app is uploaded in the play store it provides the pre-launch report of your app which displays the result of the test that google play performs on your app including accessibility.
Lint :
Lint will display the warning if contentDescription is provided to the UI elements.
Automated testing :
Espresso and Robolectric provide a way to write test cases to check the accessibility.
import androidx.test.espresso.accessibility.AccessibilityChecks
@RunWith(AndroidJUnit4::class)
@LargeTest
class MyWelcomeWorkflowIntegrationTest {
init {
AccessibilityChecks.enable()
}
}
By default, the checks run when you perform any view action defined in ViewActions. Each check includes the view on which the action is performed as well as all descendant views. You can evaluate the entire view hierarchy of a screen during each check by passing true into setRunChecksFromRootView(), as shown in the following code snippet:
AccessibilityChecks.enable().setRunChecksFromRootView(true)
That’s it we have completed accessibility integration and testing. Hope this blog gives you an overview of how we can provide accessibility. To know more about accessibility check out the official documentation https://developer.android.com/guide/topics/ui/accessibility/apps .
Happy learning
Team Appmetry