layout中的xml檔案提示Missing contentDescription attribute on image

dj0379發表於2015-10-22

(2012-11-14 16:00:42)

       使用ADT 16.0或者以上版本時,使用者定義一個ImageView,會提示[Accessibility] Missing contentDescription attribute on image,雖說這個警告可以忽略不計,但總讓人感覺不舒服。

     其實,這是ADT 16.0的新特性,在一些沒有文字顯示的控制元件裡,如imageView和imageButton等,ADT會提示你新增一個android:contentDescription屬性,用來描述這個控制元件的作用。(而且值引用strings.xml檔案中的,否則又會有提示。)

英文原文如下: 

Resolved this warning by setting attribute android:contentDescription for my ImageView
android:contentDescription="@string/desc"
Android Lint support in ADT 16 throws this warning to ensure that image widgets provide a contentDescription
This defines text that briefly describes content of the view. This property is used primarily for accessibility. Since some views do not have textual representation this attribute can be used for providing such.
Non-textual widgets like ImageViews and ImageButtons should use the contentDescription attribute to specify a textual description of the widget such that screen readers and other accessibility tools can adequately describe the user interface.

相關文章