【问题标题】:how to add strings to the string.xml如何将字符串添加到 string.xml
【发布时间】:2016-12-06 14:09:01
【问题描述】:

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

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 中,然后将它们调用到我的班级。这真的有助于整理我的代码。

【问题讨论】:

标签: java android xml string


【解决方案1】:

像这样将它们添加到您的strings.xml

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

然后您可以通过调用 ActivityFragment 或任何其他具有 Context 引用的类来获取它

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-09
    • 2023-04-03
    • 2020-04-15
    • 1970-01-01
    • 2018-02-18
    • 1970-01-01
    相关资源
    最近更新 更多