标签:
You can reference your string resources in your source code and other XML files using the resource name defined by the <string>
element‘s name
attribute.
In your source code, you can refer to a string resource with the syntax R.string.<string_name>
. There are a variety of methods that accept a string resource this way.
For example:
// Get a string resource from your app‘s Resources
String hello = getResources()
.getString(R.string.hello_world);
// Or supply a string resource to a method that requires a string
TextView textView = new TextView(this);
textView.setText(R.string.hello_world);
In other XML files, you can refer to a string resource with the syntax @string/<string_name>
whenever the XML attribute accepts a string value.
For example:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
标签:
原文地址:http://www.cnblogs.com/sansansan/p/5143818.html