eclipse 有什么方法可以抑制布局文件中有关“硬编码字符串”的警告?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9362308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:44:42  来源:igfitidea点击:

any way to suppress warnings about "hardcoded strings" in layout files?

androideclipse

提问by ycomp

Is there a way I can suppress individual warnings about hardcoded strings in layout files?

有没有办法可以抑制有关布局文件中硬编码字符串的个别警告?

I often put placeholder text into TextViews so that I can see them in layout at design time. The downside of this is getting a ton of these warnings about hardcoded strings. But without them I wouldn't see the TextViews at all in the layout.

我经常将占位符文本放入 TextViews 中,以便我可以在设计时在布局中看到它们。这样做的缺点是收到大量关于硬编码字符串的警告。但是如果没有它们,我将在布局中根本看不到 TextViews。

采纳答案by Luis

In Eclipse, go to Window->Preferences->Android->Lint Error Checking.

在 Eclipse 中,转到 Window->Preferences->Android->Lint Error Checking。

Scroll down to and selectHardcoded Text (under Internationalization). On the Severity drop down box, select Ignore and click on Apply.

向下滚动并选择硬编码文本(在国际化下)。在严重性下拉框中,选择忽略并单击应用。

回答by Clint Eastwood

You can add the following to the text view element:

您可以将以下内容添加到文本视图元素中:

tools:ignore="HardcodedText"

Example:

例子:

    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is a hardcoded text"
        tools:ignore="HardcodedText" />

Note there is a shortcut in Eclipse for adding this easily: just press CTRL + 1 and select the relevant option.

请注意,Eclipse 中有一个快捷方式可以轻松添加:只需按 CTRL + 1 并选择相关选项。

Unfortunately, I couldn't find a way to do this for a whole layout, you will have to do it for each element.

不幸的是,我找不到对整个布局执行此操作的方法,您必须为每个元素执行此操作。

Note that you must also add the xmlns:tools="http://schemas.android.com/toolsattribute to the root element

请注意,您还必须将xmlns:tools="http://schemas.android.com/tools属性添加到根元素

回答by Romain Piel

The other way is to use tools:textinstead of android:text:

另一种方法是使用tools:text代替android:text

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:text="This is a hardcoded text" />

Note that you must also add the xmlns:tools="http://schemas.android.com/toolsattribute to the root element

请注意,您还必须将xmlns:tools="http://schemas.android.com/tools属性添加到根元素

回答by Samir Mangroliya

Use string.xmlfile to remove this warning....

使用string.xml文件删除此警告....

You have to put your string in string.xml file and then give like android:text="@string/mytext"

你必须把你的字符串放在 string.xml 文件中,然后像 android:text="@string/mytext"

And in res-->value->string.xml add <string name="mytext">Your Text</string>

而在 res-->value->string.xml add <string name="mytext">Your Text</string>

http://tools.android.com/tips/lint

http://tools.android.com/tips/lint