Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 19  Accessibility


However, there is a problem. To see it for yourself, enter the title “Sticker vandalism.” Then press on
the EditText. TalkBack announces, “Edit box. Sticker vandalism” (Figure 19.10).


Figure 19.10  EditText with crime title


The problem is that TalkBack users lose context about what the EditText represents once they enter
a title. Sighted users can see that the EditText is for the title because of the TextView above it that
serves as a label. Given that crime data is pretty simple, TalkBack users could probably infer what the
EditText is for based on its contents. But this means you are making TalkBack users do more work
than non-TalkBack users.


You can easily provide the same context for TalkBack users by indicating the relationship between the
TextView and EditText. Do this by adding an android:labelFor attribute to the label in your layout
file.


Listing 19.5  Setting label for EditText (res/layout/fragment_crime.xml)


<TextView
style="?android:listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/crime_title_label"
android:labelFor="@+id/crime_title"/>

Free download pdf