【问题标题】:"Message description not found" warnings in strings.xmlstrings.xml 中的“未找到消息描述”警告
【发布时间】:2013-12-09 15:15:50
【问题描述】:

我从我的 strings.xml 收到大量烦人的警告。在每个声明的左侧,我都会收到一条警告,上面写着“找不到消息描述。”。我该如何解决?

【问题讨论】:

    标签: android xml eclipse


    【解决方案1】:

    我有同样的问题,因为我已经更新了 SDK。我找到了解决这个问题的方法。只需在您的 string.xml 文件中的每个字符串之前添加注释,这将解决警告。

    示例如下:

    <!-- Description here -->
    <string name="app_name">Test App</string>
    

    【讨论】:

    • 那么警告是因为没有注释来描述每个字符串吗?糟糕的!我会试试的,谢谢!
    • 看来,如果您的应用程序中有任何字符串的描述字符串(例如本地化服务),它会对每个未注释的字符串发出警告。
    【解决方案2】:

    这个前夜的一个适当的解决方法是: [注意文件名在大多数情况下并不准确,仅供参考]

    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>
    

    【讨论】:

      【解决方案3】:

      确保您在 strings.xml 中有资源,然后您可以尝试刷新。如果仍然有错误,请尝试关闭项目,然后重新打开它。如果所有这些都不起作用,请尝试清理项目。

      【讨论】:

      • -1 因为 OP 没有错误,这些只是经典的故障排除步骤。
      【解决方案4】:

      我相信这会解决它。将android:contentDescription=”@string/description” 添加到您的 xml。描述的目的是为了便于访问。它不是必需的,没有它您的应用程序将正常运行。但是,养成包含它的习惯是一种好习惯。

      【讨论】:

      • 谢谢,应该在哪个xml和哪个tag中添加呢?
      • 使用strings.xml的视图。所以你在哪里声明你的属性。
      • @Binghammer 警告在“strings.xml”中,布局文件中没有警告/错误。使用字符串的视图很多,你是说都需要内容描述属性?
      • @BenWilkinson 他们什么都需要。这是出于可访问性目的。
      【解决方案5】:

      您可以轻松禁用此 lint 警告。

      右键单击“问题”窗口中的警告,然后单击“快速修复”。然后您可以禁用对文件、项目或任何地方的检查。

      【讨论】:

      • 禁用警告从来都不是解决方案。我解释说:如果我想清除警告,那是因为我关心警告。更好的解决方案是简单地闭上眼睛。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-02
      • 2018-03-31
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      • 2022-07-19
      • 1970-01-01
      相关资源
      最近更新 更多