Chapter 19 Accessibility
Making a widget focusable
The problem is that the ImageView is not registered to receive focus. Some widgets, such as Buttons
and CheckBoxes, are focusable by default. Other widgets, such as TextViews and ImageViews, are not.
You can make a view focusable by setting its android:focusable attribute to true or by adding a click
listener.
Make the crime photo’s ImageView focusable by explicitly setting focusable to true in the layout
XML.
Listing 19.3 Making the crime photo ImageView focusable
(res/layout/fragment_crime.xml)
<ImageView
android:id="@+id/crime_photo"
...
android:contentDescription="@string/crime_photo_no_image_description"
android:focusable="true" />
Run CriminalIntent again and press on the crime photo. The ImageView now accepts focus and
TalkBack announces, “Crime scene photo (not set)” (Figure 19.7).
Figure 19.7 Focusable ImageView