Android:在样式xml文件中包含内容描述

发布于 2025-01-06 18:06:07 字数 719 浏览 3 评论 0原文

在开始在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恬淡成诗 2025-01-13 18:06:07

请参阅 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文