gpt4 book ai didi

What is android:contentDescription="@string/desc" in ImageView's xml?(在ImageView的XML中,android:content Description=“@string/desc”是什么?)

转载 作者:bug小助手 更新时间:2023-10-25 20:38:43 31 4
gpt4 key购买 nike



I added an imageView in GraphicalLayout but it looks different on my real device than on AVD.

我在GraphicalLayout中添加了一个ImageView,但它在我的实际设备上看起来与在AVD上不同。



I found that I need to add contentDescription in a layout .xml, but when I add: contentDescription="@string/desc"

我发现我需要在一个布局.xml中添加Content Description,但是当我添加:Content Description=“@string/desc”时



there is an error:

有一个错误:




"No resource found that matches the given name (at 'contentDescription' with value '@string/desc')"




What is this string "desc"? What should it looks like?

这个字符串“desc”是什么?它应该是什么样子?


更多回答
优秀答案推荐

It's for the Accessibility Features of Android. The contentDescription is what get's read back to the (assumingly blind or hard-of-sight user) so they have an idea of what the picture is since they aren't able to view it.

它是针对Android的无障碍功能的。Content Description是Get回读给(假设是盲人或视力不好的用户)的内容,这样他们就可以知道图片是什么,因为他们无法查看它。



As to answer your question, @iturki gives the start of it. You write the string to use for the description in strings.xml and give it a name of 'desc' or whatever your heart desires, then you set the value of contentDescription in the ImageView to @string/desc, either in the layout or programmatically. Like I said before, it's to help users with poor eyesight get a general idea of what the image is portraying :)

至于回答你的问题,@iturki是它的开始。您可以编写字符串以用于字符串.xml中的描述,并将其命名为‘desc’或您想要的任何名称,然后在ImageView中将ContDescription的值设置为@string/desc,无论是在布局中还是以编程方式。就像我之前说的,它是为了帮助视力不佳的用户大致了解图像所描绘的是什么:)



That's for Accessibility (e.g., for a screen reader). You should define a string resource that describes the image, and reference it in contentDescription. See iturki's answer for how to do this.

这是为了便于访问(例如,对于屏幕阅读器)。您应该定义一个描述图像的字符串资源,并在ContDescription中引用它。关于如何做到这一点,请参见伊图尔基的答案。



You need to add it in your string.xml file:

您需要将其添加到string.xml文件中:



<string name="desc">your desc goes here</string>


Although I don't know why you NEED to add contentDescription to your imageView to solve the inconsistent look problem! I don't think this will solve it.

虽然我不知道您为什么需要在您的ImageView中添加Content Description来解决外观不一致的问题!我认为这解决不了问题。



if you do not want to add desc , it will be fix by adding this line :

如果您不想添加desc,可以通过添加以下行进行修复:


tools:ignore="ContentDescription"


Instead of using Content description and string description just use
tools:ignore="ContentDescription" on your image view

不要使用内容描述和字符串描述,只需在图像视图上使用工具:ignore=“ContentDescription”



public void setContentDescription (CharSequence contentDescription) Defines text that briefly describes content of the view.

PUBLIC VOID setContent Description(CharSequence Content Description)定义简要描述视图内容的文本。




A content description briefly describes the view and is primarily used for accessibility support to determine how a view should be presented to the user. In the case of a view with no textual representation, such as ImageButton, a useful content description explains what the view does. For example, an image button with a phone icon that is used to place a call may use "Call" as its content description. An image of a floppy disk that is used to save a file may use "Save".



更多回答

It's not technically an error, it's a warning saying that the Accessibility isn't as good as it could be. Adding a string to contentDescription just gives TalkBack, or whichever Accessibility app the user has, content to read back to describe the image, since it's not physically viewable by the impaired user.

从技术上讲,这并不是一个错误,而是一个警告,说明可访问性并没有达到应有的水平。在ContentDescription中添加一个字符串只会给Talkback或用户拥有的任何辅助功能应用程序提供内容来描述图像,因为受损的用户无法实际查看。

And for purely decorative images, you can set android:contentDescription="@null" to no content description.

对于纯粹的装饰性图片,可以将android:Content Description=“@NULL”设置为无内容描述。

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com