Table of content
- What is Accessibility in Android
- Common Accessibility Concepts
- Overview of Accessibility in Android
- Accessibility Service and the Accessibility Model
- Making apps more accessible
- Principles to Improve Accessibility
- Final Takeaway
What is Accessibility in Android
Accessibility in Android refers to the set of features and tools provided by the Android operating system to ensure that mobile devices are usable by individuals with disabilities.
Android’s accessibility features are designed to make smartphones and tablets more inclusive and user-friendly for people who have various physical, sensory, or cognitive impairments.
Thinking deeper about accessibility in general will also help to build better UI, which will be a good thing for all the users.
Common Accessibility Concepts
- Providing appropriate labels for UI elements.
- Ensuring proper color contrast so user can easily read text and identify icons
- Providing sufficiently large touch targets so that users can interact.
Overview of Accessibility in Android
In Android R version, going deep into the Settings screen
- Find Accessibility -> click on it. This option will launch the Accessibility Settings Screen.
- This screen where a user can modify a device’s settings to make their device more functional for them.
- Under the Downloaded app, there is Accessibility Scanner, Voice access which help users control their devices with spoken command. Users can use their voice to open apps, navigate, edit text hands-free.
- Under Screen Readers, which are often used by blind and visually impaired users.
- The Talkback option, a commonly used screen reader that is probably already installed on the device, allows users to interact with a device using touch and spoken feedback.
- Select to Speak is useful for getting spoken feedback only at certain times. Users select items on the screen to hear them read or described aloud, or they point to the camera at something in the real world.
- Then we can find the settings for changing a device’s display. These settings can be used by visually impaired users or those who may struggle with the device’s default color settings.
- This section includes settings for changing the font and display size, toggling between light and dark themes, using magnification, and turning on color correction and color inversion.
- Next are settings related to interaction controls on the device. This includes Switch Access, which lets users interact with their Android devices using one or more switches instead of the touchscreen.
- Switch Access is typically used by users who may not be physically capable of touching the device screen.
- Here is a way in which the user can set how long ephemeral or short-lived Content should be displayed by the option Time to take action. This includes things like Toasts, SnackBars etc which can sometimes dismiss a little too quickly.
- In the next section after this contains settings related to audio and onscreen text. This settings can be used to enhance the audio quality when using headphones and to customize how audio is emitted on the device.
- There is an option for transcribing speech to text and for captioning media.
- There is some Experimental settings related to high-contrast text, and a shortcut related to turning on accessibility features from the lock screen.
Accessibility Service and the Accessibility Model
Accessibility Services ~ are long running privilege services that provide an alternative way for users with disabilities to interact with Android devices. It can be think of as plug-ins that change the way the UI works on a device for the user.
-
TalkBack - commonly used by blind and visually impaired users. When using TalkBack, users discovers content by moving their fingers across the device screen and TalkBack announces the views and users can interact with those view using familiar gestures. It removes the assumption that the user can see but leans into theirs ability to hear and touch the screen with precision.
-
Switch Access - When using this, a user connects two or more switches to a device. Typically, one switch is used to navigate between the different controls on the screen and the second switch is used to interact with those controls.
-
Voice Access - The user interacts with the screen entirely using voice commands.
Both Switch Access and Voice Access remove the assumption that user can actually touch the screen.
Android Interaction Model ~ Android’s accessibility interaction model is designed to ensure that users with a wide range of disabilities can effectively use and interact with the device’s interface and applications.
App with standard views, and majority of the time, these views will present information and allow users to perform actions using Android framework’s or by default Accessibility Services of choice with little effort on the app development part.
Example of Interacting with Toggle Switch in android app with TalkBack, it gives ->
- Label (text related to the switch)
- state of the control (off/on)
- control type
- action to interact with that control (double tap to activate)
In Some cases, android framework does not able to read out the label of the widgets/components. There, it is important to add “Content description” in the form of localized string and that will describe to purpose of the widget/component.
Making apps more accessible
1.Increase text visibility ~
-
If the text is smaller than 18pt, or if the text is bold and smaller than 14pt, set the color contrast ratio to at least 4.5:1.
-
For all other text, set the color contrast ratio to at least 3:1.
- Use large, simple controls ~
-
Each interactive UI element have a focusable area, or touch target size, of at least 48dpx48dp. Larger is even better. To have a large enough touch target size, the following conditions should both be true :
- The sum of the values of android:paddingLeft, android:minWidth, and android:paddingRight is greater than or equal to 48dp.
- The sum of the values of android:paddingTop, android:minHeight, and android:paddingBottom is greater than or equal to 48dp.
Example of Touch target area :
<ImageButton ...
android:paddingLeft="4dp"
android:minWidth="40dp"
android:paddingRight="4dp"
android:paddingTop="8dp"
android:minHeight="32dp"
android:paddingBottom="8dp" />
- Describe each UI element ~
For each UI element in any app, include a description that describes the element’s purpose. In most cases, one should include this description in the element’s contentDescription attribute.
<!-- Use string resources for easier localization. -->
<!-- The en-US value for the following string is "Inspect". -->
<ImageView
...
android:contentDescription="@string/inspect" />
Points to be noted :
-
If selecting a button causes a “submit” action to occur in your app, make the button’s description “Submit”, not “Submit button”.
-
Each description must be unique. That way, when screen reader users encounter a repeated element description, they correctly recognize that the focus is on an element that already had focus earlier.
-
If the app’s minSdkVersion is 16 or higher, one can set the android:importantForAccessibility attribute to “no” for graphical elements that are only used for decorative effect.
Principles to Improve Accessibility
To help people with accessibility needs use any app successfully, One app must follow the best practices.
-
Label elements - Users must be able to understand the content and purpose of each interactive and meaningful UI element within the app.
- Editable Elements - When labeling editable elements, such as EditText objects, it’s helpful to show text that gives an example of valid input in the element itself. In the below example, the attribute android:hint will do the work.
<!-- The hint text for en-US locale would be "Apartment, suite, or building". --> <EditText android:id="@+id/addressLine2" android:hint="@string/aptSuiteBuilding" ... />
- Pairs of elements where one describes the other - It’s common for an EditText element to have a corresponding View object that describes what users must enter in the EditText element. One can indicate this relationship by setting the View object’s android:labelFor attribute.
<!-- Label text for en-US locale would be "Username:" --> <TextView android:id="@+id/usernameLabel" ... android:text="@string/username" android:labelFor="@+id/usernameEntry" /> <EditText android:id="@+id/usernameEntry" ... /> <!-- Label text for en-US locale would be "Password:" --> <TextView android:id="@+id/passwordLabel" ... android:text="@string/password android:labelFor="@+id/passwordEntry" /> <EditText android:id="@+id/passwordEntry" android:inputType="textPassword" ... />
- Elements in a collection - When adding labels to the elements of a collection, each label must be unique. This way, the system’s accessibility services can refer to exactly one on-screen element when announcing a label.
data class MovieRating(val title: String, val starRating: Integer) class MovieRatingsAdapter(private val myData: Array<MovieRating>): RecyclerView.Adapter<MovieRatingsAdapter.MyRatingViewHolder>() { class MovieRatingViewHolder(val ratingView: ImageView) : RecyclerView.ViewHolder(ratingView) override fun onBindViewHolder(holder: MyRatingViewHolder, position: Int) { val ratingData = myData[position] holder.ratingView.contentDescription = "Movie ${position}: " + "${ratingData.title}, ${ratingData.starRating} stars" } }
-
Groups of related content - If the app displays several UI elements that form a natural group, such as details of a song or attributes of a message, arrange these elements within a container, which is usually a subclass of ViewGroup.
- Set the container object’s android:screenReaderFocusable attribute to true,
- and each inner object’s android:focusable attribute to false.
This way, accessibility services can present the inner elements’ content descriptions, one after the other, in a single announcement.
Note: On Android 4.4 (API level 19) and lower, the android:screenReaderFocusable attribute isn’t available, so set the container’s android:focusable attribute instead.
<!-- In response to a single user interaction, accessibility services announce both the title and the artist of the song. --> <ConstraintLayout android:id="@+id/song_data_container" ... android:screenReaderFocusable="true"> <TextView android:id="@+id/song_title" ... android:focusable="false" android:text="@string/my_song_title" /> <TextView android:id="@+id/song_artist" android:focusable="false" android:text="@string/my_songwriter" /> </ConstraintLayout>
-
Headings within text - If a particular View element represents a heading, one can indicate its purpose for accessibility services by setting the element’s android:accessibilityHeading attribute to true.
-
Accessibility pane titles - In Android 9 (API level 28) and higher, one can provide accessibility-friendly titles for a screen’s panes. For accessibility purposes, a pane is a visually distinct portion of a window, such as the contents of a fragment. To specify the title of a pane, use the android:accessibilityPaneTitle attribute.
<!-- Accessibility services receive announcements about content changes that are scoped to either the "shopping cart view" section (top) or "browse items" section (bottom) --> <ShoppingCartView android:id="@+id/shoppingCartContainer" android:accessibilityPaneTitle="@string/shoppingCart" ... /> <ShoppingBrowseView android:id="@+id/browseItemsContainer" android:accessibilityPaneTitle="@string/browseProducts" ... />
-
Add accessibility actions - It’s important to allow users of accessibility services to easily perform all user flows within the app.
- Make all actions accessible - For actions associated with gestures such as drag-and-drop or swipes, the app can expose the actions in a way that is accessible to users of accessibility services.
For example, if the app allows users to swipe on an item, one can also expose the functionality through a custom accessibility action, like this:
ViewCompat.addAccessibilityAction( // View to add accessibility action itemView, // Label surfaced to user by an accessibility service getText(R.id.archive) ) { _, _ -> // Same method executed when swiping on itemView archiveItem() true }
-
Make available actions understandable - When a view supports actions such as touch & hold, an accessibility service such as TalkBack announces it as “Double tap and hold to long press.” This generic announcement doesn’t give the user any context about what a touch & hold action does.
To make this announcement more descriptive, one can replace the accessibility action’s announcement like below example. This results in TalkBack announcing “Double tap and hold to favorite,” helping users understand the purpose of the action.
ViewCompat.replaceAccessibilityAction( // View that contains touch & hold action itemView, AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_LONG_CLICK, // Announcement read by TalkBack to surface this action getText(R.string.favorite), null )
-
Extend system widgets -It’s easier to extend these system-provided widgets than to create your own widget from the more generic View, ViewCompat, Canvas, and CanvasCompat classes.
- **Define custom events -**When one extends a system widget, one likely change an aspect of how users interact with that widget. It’s important to define these interaction changes so that accessibility services can update the app’s widget as if the user interacts with the widget directly.
A general guideline is that for every view-based callback one can override, and also need to redefine the corresponding accessibility action by overriding
ViewCompat.replaceAccessibilityAction()
One can validate the behavior of these redefined actions by calling
ViewCompat.performAccessibilityAction()
Practice : CodeLab example of Android app accessibility
Final Takeaway
The Accessibility features and tools make Android devices more inclusive and user-friendly for a broad range of users. They aim to ensure that people with disabilities can independently and effectively use their Android smartphones and tablets to access information, communicate, and perform tasks in their daily lives. Android’s commitment to accessibility aligns with broader goals of promoting digital inclusion and ensuring that technology is accessible to everyone.