我从字符串.xml中收到了大量令人讨厌的警告。在每个声明的左侧,我都会收到一条警告,上面写着"找不到消息描述"。我该如何修复它?
我也有同样的问题,因为我已经更新了SDK。我找到了解决这个问题的办法。只需在string.xml文件中的每个字符串之前添加一个注释,就可以解决警告。
以下示例:
<!-- Description here -->
<string name="app_name">Test App</string>
尽管这个eve比较旧,但一个合适的修复方法是:[注意文件名在大多数情况下并不准确,只是一个指南]
1. In your fragment_main.xml (/ProjectName/res/layout/fragment_main.xml)
change your view and add this:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!-- Add this one line below as "contentDescription" refers to this issue
of description not found warning by Lint -->
android:contentDescription="@string/description"
android:text="@string/hello_world" />
2. The @string references the strings in your strings.xml and the name
of the string itself is "description"
So in your ProjectName/res/values/strings.xml add:
<string name="description">Variables</string>
确保strings.xml中有资源,然后可以尝试刷新。若您仍然有错误,请尝试关闭项目,然后重新打开它。若所有这些都不起作用,请尝试清理项目。
我相信这会解决问题。将android:contentDescription=”@string/description”
添加到您的xml中。描述的目的是为了便于访问。它是不需要的,没有它你的应用程序将正常运行。然而,养成包括它的习惯是一个很好的做法。
您可以轻松禁用此lint警告。
右键单击"问题"窗口中的警告,然后单击"快速修复"。然后可以禁用对文件、项目或所有位置的检查。