imagebutton给我错误:[辅助功能]图像上缺少contentDescription属性

时间:2012-01-02 13:45:49

标签: android accessibility imagebutton

[辅助功能]图像上缺少contentDescription属性

这个错误意味着什么,我该如何解决?

<ImageButton
    android:id="@+id/callbannerbuttonpg1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="157dp"
    android:background="@null"
    android:src="@drawable/callbanner"
    android:visibility="invisible" />

4 个答案:

答案 0 :(得分:18)

Designing for Accessibility

“定义简要描述视图内容的文本。此属性主要用于辅助功能。由于某些视图没有文本表示,因此可以使用此属性来提供此类属性。”

这不是错误只是一个警告。此属性的使用是可选的。

答案 1 :(得分:5)

在imageButton中使用此行

机器人:contentDescription = “@串/ desc” 的

答案 2 :(得分:3)

只需添加:

android:contentDescription="@string/description"

然后转到你的 Strings.xml 并添加:

<string name="description"> YOUR_DESCRIPTION_HERE </string>

您的代码:

<ImageButton
    android:id="@+id/callbannerbuttonpg1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="157dp"
    android:background="@null"
    android:src="@drawable/callbanner"
    android:visibility="invisible"
    android:contentDescription="@string/description" />

答案 3 :(得分:0)

您也可以通过将其添加到imageButton标记中来忽略此类警告:

tools:ignore="contentDescription"
相关问题