我收到警告,因为"[可访问性]在图像上缺少contentDescription属性"for imageview.而使用android lint
那是什么意思?
辅助功能]图像上缺少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" />
Run Code Online (Sandbox Code Playgroud) 当我将 Android studio 从 3.3 更新到 3.4.1 时,我在 ImageView 标签中遇到了一些有趣的警告,例如:android:contentDescription attribute is unknown
。我该如何解决这个警告?或者是新的Android Studio 3.4.1的bug?
android android-layout kotlin android-constraintlayout androidx
<ImageView style="@style/LoaderPrevNext.Next" />
Run Code Online (Sandbox Code Playgroud)
使用样式
<style name="LoaderPrevNext">
<item name="android:layout_width">40dp</item>
<item name="android:layout_height">80dp</item>
<item name="android:layout_weight">0</item>
<item name="android:scaleType">fitXY</item>
</style>
<style name="LoaderPrevNext.Next">
<item name="android:src">@drawable/next_page</item>
<item name="android:contentDescription">@string/img_desc_next_page</item>
</style>
Run Code Online (Sandbox Code Playgroud)
[Accessibility] Missing contentDescription attribute on image
警告让我很生气.
如果我将contentDescription从样式移动或复制到ImageView标签,它就会消失,但由于src是在样式中定义的,我很乐意将它们保持在一起.
猜猜这只是一个SDK bug,但有些可能会有一个解决方法......
澄清:有问题的ImageView确实有一个内容描述,在LoaderPrevNext.Next样式中定义.警告是错误的.我对如何设置内容描述或如何将其破解为空的想法不感兴趣.