关于android的imagebutton,imageview等无文本控件警告的解决办法//android:contentDescription="@string/desc"
开发程序时,在main.xml中添加控件imagebutton时会有一下警告:
missingcontentdescriptionattributeonimage
起初不知道怎么办
后来查了一下文档知道了,官方解释如下:
resolvedthiswarningbysettingattributeandroid:contentdescriptionformyimageview
android:contentdescription="@string/desc"
androidlintsupportinadt16throwsthiswarningtoensurethatimagewidgetsprovideacontentdescription
thisdefinestextthatbrieflydescribescontentoftheview.thispropertyisusedprimarilyforaccessibility.sincesomeviewsdonothavetextualrepresentationthisattributecanbeusedforprovidingsuch.
non-textualwidgetslikeimageviewsandimagebuttonsshouldusethecontentdescriptionattributetospecifyatextualdescriptionofthewidgetsuchthatscreenreadersandotheraccessibilitytoolscanadequatelydescribetheuserinterface.
大体翻译一下:
解决警告missingcontentdescriptionattributeonimage的方法是添加一下代码
android:contentdescription="@string/desc"(注意,这里的desc指的是你对自己程序的描述,这段描述定义在string.xml里面)
提示:其实这段描述是什么这个不重要,你可以引用string里面的任何一个字符串
安卓Android的这个adt16发出这个警告的目的是为了让你对已定义的image控件进行描述
控件的这一特性主要是起到辅助作用的。由于无文本控件没有描述性功能的文字说明,所以imagebutton,imageview这些控件描述性的定义就能起到与代码阅读者或者是其他工具进行衔接的功能!