我一直在到处寻找一种允许从文本文件中读取@string 值的方法。我不确定我是否完全清楚,因为我似乎无法用语言描述它,所以我将使用这个 fragment 。
This is a <@string/square_root>
因此,当我将文件读入 TextView 时,它包含平方根符号。 这可能吗?或者是否有其他方法可以做到这一点。
最佳答案
执行此操作的标准方法是将您的字符串放入资源文件中,通常是 res/values/strings.xml(注意下面的 221A 是平方根符号的 Unicode 值)。
<string name="square_root">\u221A</string>
然后您可以从 XML 布局文件中引用此字符串:
<TextView android:text="@string/square_root" ...>
或者来自 Java 代码:
Context context = this; // in this example the current activity is the context
String title = context.getString(R.string.square_root);
TextEdit textEdit = ....
textEdit.setText(title);
有关详细信息,请参阅:http://developer.android.com/guide/topics/resources/string-resource.html
关于android - 从文本文件中读取字符串值到 textView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14116446/