如何将字符串添加到string.xml

时间:2016-12-06 14:09:01

标签: java android xml string

大家好我在我的一个课程中有很多公共字符串,如下所示。

public String HeadlightString = "lights not satisfactory", 
ReflectorString = "Reflectors and warning devices not satisfactory",
HornString = "Horn and other warnings not satisfactory", 
MirrorsString = "Mirrors not satisfactory", 
BrakessystemStrings = "Problem with the brakes System";

如何将它们添加到我的string.xml然后将它们调用到我的类。这真的有助于整理我的代码。

1 个答案:

答案 0 :(得分:0)

将这些内容添加到strings.xml

<string name="HeadlightString">lights not satisfactory</string>

然后,您可以通过致电ActivityFragment或任何其他具有Context参考的课程来获取

String headlightString = getString(R.string.HeadlightString);