2011-12-14 148 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爲所有的休息。

相關問題