字符串资源定义示例:
<?xml version="1.0" encoding="utf-8"?><resources>
<string name="hello">Hello World!</string>
</resources>
1. 在 Layout XML 调用字符串资源:
<TextViewandroid:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
2. 在 Activity 获取字符串资源:
this.getString(R.string.hello)
3. 从 Context 获取字符串资源:
context.getResources().getString(R.string.hello)
4. 从 Application 获取字符串资源:
application.getString(R.string.hello)
举例:
// code inside an Activity method
String helloWorld = this.getResources().getString(R.string.hello_world);
int anInt = this.getResources().getInteger(R.integer.an_int);