Java EclipseAndroid开发-“I18N]硬编码字符串”;TextView";,应该使用@string资源
我是android开发的新手,尝试创建一个名为new_layout.xml的新布局,我在Lynda培训课程中看到了它,代码如下,效果很好。但每次我关闭Eclipse和AVD并稍后启动时,xml文件中都会出现一些错误:Java EclipseAndroid开发-“I18N]硬编码字符串”;TextView";,应该使用@string资源,java,android,xml,eclipse,sdk,Java,Android,Xml,Eclipse,Sdk,我是android开发的新手,尝试创建一个名为new_layout.xml的新布局,我在Lynda培训课程中看到了它,代码如下,效果很好。但每次我关闭Eclipse和AVD并稍后启动时,xml文件中都会出现一些错误: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" /> <!-- [I18N] Hardcoded string "TextView", should use @string resource -->
<EditText <!-- This text field does not specify an inputType or a hint -->
android:id="@+id/editText1"
android:layout_width="wrap_content" <!-- Use a layout_width of 0dp instead of wrap_content for better performance -->
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
android:id=“@+id/editText1”
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
android:layout_weight=“1”
android:ems=“10”
以下是突然出现的其他错误的屏幕截图:
![在此处输入图像描述][1]硬编码字符串、缺少内容描述等都不是错误,但是
Lint
与应用程序可用性相关的警告。请参阅以了解更多信息
示例:您可以将相同的字符串放入/res/values
和(例如)/res/values de
文件夹中。如果设备语言为德语,系统将从符合-de
的文件夹中获取字符串。硬编码字符串意味着无论设备设置如何,它都将保持不变
这不是一个错误,而是可用性的问题。这同样适用于所有
Lint
警告。硬编码字符串、缺少内容描述等都不是错误,但Lint
警告与应用程序的可用性有关。请参阅以了解更多信息
示例:您可以将相同的字符串放入/res/values
和(例如)/res/values de
文件夹中。如果设备语言为德语,系统将从符合-de
的文件夹中获取字符串。硬编码字符串意味着无论设备设置如何,它都将保持不变
这不是一个错误,而是可用性的问题。这同样适用于所有
Lint
警告。Eclipse鼓励您使用strings.xml
文件来声明字符串,而不是像您现在这样将它们硬编码到其他项目文件中
strings.xml
文件可以在项目的res/values/strings.xml
中找到。只需像中所示将字符串放置在此文件中,并在其他项目文件中引用这些字符串
下面是一个可能的示例:new_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textView" /> <!-- [I18N] Hardcoded string "TextView", should use @string resource -->
<EditText <!-- This text field does not specify an inputType or a hint -->
android:id="@+id/editText1"
android:layout_width="wrap_content" <!-- Use a layout_width of 0dp instead of wrap_content for better performance -->
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button" />
<resources>
<string name="textView">TextView</string>
<string name="button">Button</string>
</resources>
android:id=“@+id/editText1”
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
android:layout_weight=“1”
android:ems=“10”
res/values/strings.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textView" /> <!-- [I18N] Hardcoded string "TextView", should use @string resource -->
<EditText <!-- This text field does not specify an inputType or a hint -->
android:id="@+id/editText1"
android:layout_width="wrap_content" <!-- Use a layout_width of 0dp instead of wrap_content for better performance -->
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button" />
<resources>
<string name="textView">TextView</string>
<string name="button">Button</string>
</resources>
文本框
按钮
由于屏幕截图链接不正确,我只有标题,希望这会有所帮助。Eclipse鼓励您使用
strings.xml
文件来声明字符串,而不是像您这样将它们硬编码到其他项目文件中
strings.xml
文件可以在项目的res/values/strings.xml
中找到。只需像中所示将字符串放置在此文件中,并在其他项目文件中引用这些字符串
下面是一个可能的示例:new_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textView" /> <!-- [I18N] Hardcoded string "TextView", should use @string resource -->
<EditText <!-- This text field does not specify an inputType or a hint -->
android:id="@+id/editText1"
android:layout_width="wrap_content" <!-- Use a layout_width of 0dp instead of wrap_content for better performance -->
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button" />
<resources>
<string name="textView">TextView</string>
<string name="button">Button</string>
</resources>
android:id=“@+id/editText1”
android:layout\u width=“包装内容”
android:layout\u height=“包装内容”
android:layout_weight=“1”
android:ems=“10”
res/values/strings.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textView" /> <!-- [I18N] Hardcoded string "TextView", should use @string resource -->
<EditText <!-- This text field does not specify an inputType or a hint -->
android:id="@+id/editText1"
android:layout_width="wrap_content" <!-- Use a layout_width of 0dp instead of wrap_content for better performance -->
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button" />
<resources>
<string name="textView">TextView</string>
<string name="button">Button</string>
</resources>
文本框
按钮
由于屏幕截图链接不正确,我只有标题可供参考,希望这能有所帮助。谢谢。这很有帮助。我还通过使用android:inputType=“text”@neoraj3.0解决了这个问题。没问题!谢谢这很有帮助。我还通过使用android:inputType=“text”@neoraj3.0解决了这个问题。没问题!谢谢我将查看Lint文档,因为我不熟悉它。谢谢。我将查看Lint文档,因为我不熟悉它。