正如我的标题所说,如何以XML格式包含我可以通过其ID访问的资源字符串?此ID在dot42中自动生成,但我在Google中找不到任何教导。
答案 0 :(得分:1)
使用以下内容创建新文件strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="firstName">MisterFive</string>
</resources>
将其包含在项目中,并将Build Action属性设置为“ValuesResource”。
如果打开R.cs(内部属性文件夹),您将看到生成以下代码:
//------------------------------------------------------------------------------
// This file is automatically generated by dot42
//------------------------------------------------------------------------------
namespace dot42Application2
{
using System;
public sealed class R
{
public sealed class Strings
{
public const int firstName = 0x7f040000;
}
}
}
您可以像这样从C#访问您的字符串资源:
string firstName = GetString(R.Strings.firstName);
答案 1 :(得分:0)
NM!再想一想。
对于遇到此问题的任何人,请转到:
Solution Explorer > Project(Right Click) > Add > New Item > Dot42 > Android > String table resource > Build (Press F7) > Done!