首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >安卓Lint contentDescription警告

安卓Lint contentDescription警告
EN

Stack Overflow用户
提问于 2011-12-14 14:55:37
回答 9查看 116.8K关注 0票数 133

对于imageview,我收到“图像上缺少contentDescription属性的辅助功能”的警告。在使用android lint时

那是什么意思?

EN

回答 9

Stack Overflow用户

回答已采纳

发布于 2011-12-14 20:40:48

通过为我的ImageView设置属性android:contentDescription解决了此警告

代码语言:javascript
复制
android:contentDescription="@string/desc"

Android Lint在ADT16中的支持抛出此警告,以确保图像小部件提供contentDescription。

这定义了简要描述视图内容的文本。此属性主要用于辅助功能。因为有些视图没有文本表示,所以这个属性可以用来提供文本表示。

像ImageViews和ImageButtons这样的非文本小部件应该使用contentDescription属性来指定小部件的文本描述,以便屏幕阅读器和其他辅助工具能够充分描述用户界面。

票数 173
EN

Stack Overflow用户

发布于 2013-07-12 05:12:07

禁用Lint警告很容易在以后给您带来麻烦。最好只为所有ImageViews指定contentDescription。如果您不需要描述,那么只需使用:

代码语言:javascript
复制
android:contentDescription="@null"
票数 51
EN

Stack Overflow用户

发布于 2013-05-19 07:26:44

另一种选择是逐个禁止显示警告:

代码语言:javascript
复制
xmlns:tools="http://schemas.android.com/tools"  (usually inserted automatically)
tools:ignore="contentDescription"

示例:

代码语言:javascript
复制
<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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8500544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档