Accessibility in the Android world

Nav Singh
ProAndroidDev
Published in
4 min readAug 15, 2021

--

Accessibility story header

Today we will learn accessibility in general and how to implement and test it in our applications.

Accessibility

It is about making sure that users who have limited vision or other physical impairments can use your application.

Impact of accessibility

  1. Increase your app’s reach
    According to the World Bank, 15% of the world’s population has some type of disability. People with disabilities depend on apps and services that support access to communicate, learn, and work.
  2. Improve your app’s versatility
    Accessibility can make it easier for all users to interact with your app, not only those with disabilities.

How Android enables accessibility

One of the main ways that Android enables accessibility is by allowing users to hear spoken feedback that announces the content of user interface components as they interact with applications.

How to make your application accessible

  1. Task flows: Design well-defined, clear task flows with minimal navigation steps.
  2. Action target size: Make sure buttons and selectable areas are of sufficient size for users to easily touch them, especially for critical actions. How big? (48dp (roughly 9mm) or larger).
  3. Label user interface: Label user interface components that do not have visible text.
  4. Enable focus-based navigation: Make sure users can navigate your screen layouts using hardware-based or software directional controls (D-pads, trackballs, and keyboards).

Implementation

  • Add label to decorative views like Imageview:
android:contentDescription="Application logo"
  • If the view is there just for the decorative purpose you can skip it when users accessing your app using accessibility tools e.g. Talkback:
android:contentDescription="@null"OR android:importantForAccessibility="no"
  • Setting text as the heading:
// only avaialble for API 28 or higherandroid:accessibilityHeading="true"
  • Set the view to be focusable for ScreenReader:
// only avaialble for API 28 or higherandroid:screenReaderFocusable="true"
  • Set the navigation between views:
 android:nextFocusDown="@id/textview_2" android:nextFocusLeft="view id" android:nextFocusUp="view id" android:nextFocusRight="view id"
  • Set Textview as a label for any other field e.g. EditText:
android:labelFor="view id"
  • Set how accessibility services process the view changes:
android:accessibilityLiveRegion="none || assertive || polite"
  • Process the view as a single group:
// add the following properties to the parent tag
android:focusable="true"
OR// only avaialble for API 28 or higher
android:screenReaderFocusable="true"

Color contrast

The colors of your app’s interface affect how easily users can read and understand it. So make sure that there is a sufficient color contrast that makes text and images easier to read and understand.

Implementation

  • In your app’s user interface, specify background and foreground colors with sufficient color contrast.
  • For TextView use android:textColor and android:background to define foreground and background colors with a high contrast ratio.

The W3C recommends:

  • At least 4.5:1 for small text (below 18 points regular or 14 points bold)
  • At least 3.0:1 for large text (18 points and above regular or 14 points and above bold)

Test your app’s accessibility

  • Manual testing: Interact with your app using Android accessibility services.
  • Testing with analysis tools: Use tools to discover opportunities to improve your app’s accessibility(Talkback, Accessibility scanner)
  • Automated testing: Turn on accessibility testing in Espresso and Robolectric.
Enable accessibility checks in Espresso’s UI tests
  • User testing: Get feedback from real people who interact with your app.
  • Pre-launch report on Google Play

Check full sample code

Demo 🥳🥳🥳🥳

  • Accessibility scanner
Accessibility scanner in action
  • Talkback
Talkback application in action

😊😊 👏👏👏👏 HAPPY CODING 👏👏👏👏 😊😊

--

--

Google Developer Expert for Android | Mobile Software Engineer at Manulife | Organizer at GDG Montreal