Missing contentDescription attribute on image | Android XML

スポンサーリンク

スポンサーリンク

意味

content descriptionとはコンテントの説明という意味、XML内にコンテントの説明がありませんよ。という警告です。

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton"
    app:srcCompat="@drawable/ic_near_me_black_24dp"
    />

上記のようなコードの際に発生します。

ImageButtonはImageViewの子ですからImageViewと同じように発生するわけです。

解決策

android:contentDescription="クリックしたら表示"

で構いません。(実際は@stringを使います)

もし説明がない、面倒、という場合は

android:contentDescription="@null"

とすることで空にできます。

android:contentDescription="null"

nullでは、このImageButtonはnullですよという別の意味になってしまいます。

@nullは例えばButtonのbackgroundを無しにする時などにも利用できます。