Switch Name

Link to Switch Name copied to clipboard

WCAG 2.0 - 1.3.1 A Impact - Critical

Any view with a modifiable value should get its name from a nearby label.

Supported within:
XML Layouts

Impact

A switch should have a name that provides the context and expectation of what happens when it is turned on or off, especially for people with low-vision or blindness.

note

Issues may arise depending on the focus order of the switch and its name.

Confirmation

  1. Turn on TalkBack
  2. Attempt to focus on a Switch control
  3. One of the following will occur:
    • Inaccessible: TalkBack only announces 'on' or 'off'.
    • Accessible: TalkBack announces the name of the switch and 'on' or 'off'.

How to Fix

You may provide a label in the neighboring element or wrap the switch with its label. You may also manipulate the contentDescription, but be sure to retain the 'on' and 'off' state for TalkBack announcements.

layouts/activity.xml
<TextView
     android:id="@+id/label"
     android:text="@string/label_text"
     android:labelFor="@+id/switch">
<Switch
     android:id="@+id/switch"/>

...

strings.values/
<string name="label_text">Dark Mode</string>