Android:在样式xml文件中包含内容描述
在开始在 Eclipse 中使用 Android Lint 工具后,我收到了许多新警告。其中之一是说我的 ImageView 缺少 contentDescription。
对于常规 ImageView,我这样做,效果很好:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:contentDescription="@string/imgViewDesc"
....
</ImageView>
但是,如果我有一个使用样式 xml 文件的 ImageView,如下所示:
<ImageView
style="@style/TitleBarLogo"
android:src="@drawable/title_logo" />
如果我在 styles.xml 中有这样的内容:
<style name="TitleBarLogo">
<item name="android:contentDescription">@string/imgViewDesc</item>
....
</style>
警告不会 走开。
有什么办法可以解决这个问题吗?
After beginning to use the Android Lint tool in Eclipse I'm getting many new warnings. One of them is saying that my ImageViews are missing a contentDescription.
For regular ImageViews I do it like this, and it works just fine:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:contentDescription="@string/imgViewDesc"
....
</ImageView>
However, if I have an ImageView that's using a style xml file, like this:
<ImageView
style="@style/TitleBarLogo"
android:src="@drawable/title_logo" />
and if I in my styles.xml have this:
<style name="TitleBarLogo">
<item name="android:contentDescription">@string/imgViewDesc</item>
....
</style>
the warning does not go away.
Is there any way to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 http://tools.android.com/tips/lint
我认为您正在规避目的通过将内容描述放入样式中来进行描述。 contentDescription 用于识别图像以供可访问性。通过将其推迟到样式中,您将失去此 contentDescription 描述此特定图像的推论。
See http://tools.android.com/tips/lint
I think you are circumventing the purpose of contentDescription by putting it in a style. contentDescription is to identify the image for accessibility. By deferring it into the style, you are losing the inference that this contentDescription describes this particular image.