我一直在到处寻找一种允许从文本文件中读取@string 值的方法。我不确定我是否完全清楚,因为我似乎无法用语言来描述它,所以我将使用这个片段。
This is a <@string/square_root>
因此,当我将文件读入文本视图时,它包含平方根符号。这可能吗?或者如果有另一种方法可以做到这一点。
我一直在到处寻找一种允许从文本文件中读取@string 值的方法。我不确定我是否完全清楚,因为我似乎无法用语言来描述它,所以我将使用这个片段。
This is a <@string/square_root>
因此,当我将文件读入文本视图时,它包含平方根符号。这可能吗?或者如果有另一种方法可以做到这一点。
执行此操作的标准方法是将字符串放在资源文件中,通常是 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