【问题标题】:Missing contentDescription attribute on image how to remove this warning?图片上缺少 contentDescription 属性如何删除此警告?
【发布时间】:2014-04-09 08:27:17
【问题描述】:

可访问性缺少图片上的 contentDescription 属性

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="34dp"
    android:layout_height="61dp"
    android:layout_marginLeft="11dp"
    android:layout_marginRight="0dp"
    android:layout_marginTop="11dp"
    android:background="#ff3333"
    android:src="@drawable/arrows" />

【问题讨论】:

标签: android


【解决方案1】:

您可以使用布局编辑器的tools 或将android:contentDescription 设置为null

这是一个例子:

// You don't need a FrameLayout, 
// tell the layout editor what to "ignore" in your layout's parent

<FrameLayout 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:id="@+id/imageView1"
        android:layout_width="34dp"
        android:layout_height="61dp"
        android:layout_marginLeft="11dp"
        android:layout_marginRight="0dp"
        android:layout_marginTop="11dp"
        android:background="#ff3333"
        android:src="@drawable/arrows" />

</FrameLayout>

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="34dp"
    android:layout_height="61dp"
    android:layout_marginLeft="11dp"
    android:layout_marginRight="0dp"
    android:layout_marginTop="11dp"
    android:background="#ff3333"
    android:contentDescription="@null"
    android:src="@drawable/arrows" />

但更好的是,您应该考虑添加一个简短的String 以准确描述ImageView 的用途。

From the docs:

定义简要描述视图内容的文本。这个性质 主要用于可访问性。由于有些观点没有 文本表示,此属性可用于提供此类。

必须是字符串值,使用 '\;'转义字符,例如 '\n' 或 '\uxxxx' 表示 unicode 字符。

【讨论】:

    【解决方案2】:

    在您的 xml imageView 中添加以下行,它应该会消失。

     android:contentDescription:"@string/desc"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-25
      • 2021-01-16
      • 1970-01-01
      • 2017-01-03
      相关资源
      最近更新 更多