2011-12-14 135 views
120

我收到警告为 “[辅助功能]对imageview缺少image上的contentDescription属性”。同时使用android lintAndroid Lint contentDescription警告

这是什么意思?

+5

这是一个令人讨厌的警告 - 尤其是对于天才的图像 – 2012-10-24 22:48:46

+6

我在strings.xml中定义了这个:``然后我使用了`android:contentDescription =“ @ string/none“` – 2012-10-24 22:54:41

回答

159

通过设置属性android:contentDescription我的ImageView解决此警告在ADT 16

android:contentDescription="@string/desc" 

的Android林特支持抛出这个警告,以确保图像控件提供contentDescription。

这定义了简要描述视图内容的文本。该属性主要用于可访问性。由于某些视图没有文字表示,因此可以使用此属性来提供此类属性。

非文本小部件(如ImageView和ImageButton)应该使用contentDescription属性来指定小部件的文本描述,以便屏幕阅读器和其他辅助工具可以充分描述用户界面。

+3

你可以阅读更多关于它的信息,并通过自己去测试它:http://android-developers.blogspot.com/2012/04/accessibility-are-you-serving-all-your。 HTML和http://developer.android.com/guide/topics/ui/accessibility/apps.html#test – 2012-05-15 14:31:21

12

由于它只是一个警告,你可以压制它。转到您的XML的图形化布局和做到这一点:

  1. 点击右上角的红色按钮

    enter image description here

  2. 选择 “禁用问题类型”(例如)

    enter image description here

+4

诚然,你可以禁止它,但你可能应该按照所选答案的建议,为了依赖Android提供的辅助功能工具的用户。 – 2013-03-25 20:59:01

+0

这就是它!多数民众赞成我正在寻找。这个答案和@Gunnar Bernstein的回答让我感到满意。 – IronBlossom 2015-04-23 13:08:54

33

另一个op重刑是抑制个别警告:

xmlns:tools="http://schemas.android.com/tools" (usually inserted automatically) 
tools:ignore="contentDescription" 

例子:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:ignore="contentDescription" > 

     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:padding="5dp" 
      android:src="@drawable/icon" /> 
40

禁止lint警告会很容易让你陷入困境以后。您最好只为所有ImageView指定contentDescription。如果你并不需要一个说明,然后只需使用:

android:contentDescription="@null" 
18

我建议你添加contentDescription。

android:contentDescription="@string/contentDescriptionXxxx" 

但是,让我们现实一点。大多数人不保持文字的可访问性。 仍然,毫不费力,你可以实施一些东西来帮助残疾人。

<string name="contentDescriptionUseless">deco</string> 
<string name="contentDescriptionAction">button de action</string> 
<string name="contentDescriptionContent">image with data</string> 
<string name="contentDescriptionUserContent">image from an other user</string> 

最重要的事情盲人用户需要知道的是“哪里是我需要点击继续按钮”

使用contentDescriptionAction为任何点击。

使用contentDescriptionContent用于与信息图像(图中,textAsImage,...)

使用contentDescriptionUserContent所有用户提供的内容。

使用contentDescriptionUseless为所有的休息。