What is android:contentDescription=“@string/desc” in ImageView's xml?

别说谁变了你拦得住时间么 提交于 2021-02-19 03:13:42

问题


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

I found that I need to add contentDescription in a layout .xml, but when I add: contentDescription="@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?


回答1:


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

<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.




回答2:


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.

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 :)




回答3:


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.




回答4:


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




回答5:


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

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".



来源:https://stackoverflow.com/questions/11595828/what-is-androidcontentdescription-string-desc-in-imageviews-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!