我刚刚开始使用 VS2012 使用 Xamarin 创建一个简单的 Android 应用程序。
我知道有一种类型的资源仅用于字符串。
在我的资源文件夹中,我有一个如下所示的 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="RecordsTable">records</string>
<string name="ProjectTable">projects</string>
<string name="ActivitiesTable">activities</string>
</resources>
在我的代码中,我想使用这些资源的值,例如:
string recordTable = Resource.String.RecordsTable; //error, data type incompatibility
我知道Resource.String.<key>
返回一个整数,所以我不能使用上面的代码。
我希望recordTable
变量的值为records
.
有没有办法可以将这些资源字符串的值用于我的代码的字符串变量?
尝试使用资源.GetString http://docs.mono-android.net/?link=M%3aAndroid.Content.Res.Resources.GetString%28int%29#用于从字符串资源中获取字符串
Context context = this;
// Get the Resources object from our context
Android.Content.Res.Resources res = context.Resources;
// Get the string resource, like above.
string recordTable = res.GetString(Resource.String.RecordsTable);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)