Xamarin android将字符串保存到strings.xml

时间:2016-07-29 12:17:44

标签: c# android xml string xamarin

让我说我和我的Xamarin.Android应用程序EditText。我想从中获取文本并将其保存为Strings.xml中的字符串。我该怎么做?

1 个答案:

答案 0 :(得分:3)

无法以编程方式修改

ISharedPreferences sharedprefs = GetSharedPreferences("prefs_file", FileCreationMode.Private); sharedprefs.Edit().PutString("keyName","value").Commit(); 。它们是常量字符串

如果您需要保存字符串&保留它,最简单的方法是使用 SharedPreferences 将值存储为键值对。试试

 ISharedPreferences sharedprefs = GetSharedPreferences("prefs_file", FileCreationMode.Private);
 String str = sharedprefs.GetString("keyName", null);

您可以使用“keyName”检索字符串,如

{{1}}