Labeling User Interface Elements
许多用户界面控制依赖于可视化的线索(提示)来表征它的意义和用途。例如,笔记本应用利用ImageButton 附上一个图片标记,用以指示用户添加一个笔记。
一个编辑框EditText组件附近可能有一个标签表示它的用途。 对于实力不好的人,这些都没啥用处。
利用android:contentDescription XML 布局属性可以使这些控制更容易获取。如果用户启用辅助语音功能,当用户导航到这个控制,文本被播放出来。
For this reason, set the android:contentDescription
attribute for every ImageButton
, ImageView
,CheckBox
in your application's user interface, and add descriptions to any other input controls that might require additional information for users who are not able to see it.
For example, the following ImageButton
sets the content description for the plus button to the add_note
string resource, which could be defined as “Add note" for an English language interface:
<ImageButton android:id=”@+id/add_note_button” android:src=”@drawable/add_note” android:contentDescription=”@string/add_note”/>通过包含这个描述,辅助功能能够提供语音反馈,发出“Add note” 当用户moves focus to this button or hovers over it 。
Note: For EditText
fields, provide an android:hint attribute instead of a content description, to help users understand what content is expected when the text field is empty. When the field is filled, TalkBack reads the entered content to the user, instead of the hint text.
Building Accessible Custom Views
If your application requires a custom view component, you must do some additional work to ensure that your custom view is accessible. These are the main tasks for ensuring the accessibility of your view:
View
class as well as the
View.AccessibilityDelegate
class. The methods are as follows:
sendAccessibilityEvent()
TYPE_VIEW_CLICKED
. You typically do not need to implement this method unless you are creating a custom view.
sendAccessibilityEventUnchecked()
AccessibilityManager.isEnabled()
). If you do implement this method, you must perform the call as if accessibility is enabled, regardless of the actual system setting. You typically do not need to implement this method for a custom view.
dispatchPopulateAccessibilityEvent()
onPopulateAccessibilityEvent()
for this view and then the
dispatchPopulateAccessibilityEvent()
method for each child of this view. In order to support accessibility services on revisions of Android
prior to 4.0 (API Level 14) you
must override this method and populate
getText()
with descriptive text for your custom view, which is spoken by accessibility services, such as TalkBack.