Use the String Resources
You can reference your string resources in your source code and other XML files using the resource name defined by the element ' s name
attribute.
In your source code, you can refer-a string resource with the syntax R.string.<string_name>
. There is a variety of methods that the accept a string resource this.
For example:
Get a string resource from your app ' sResources
StringHello= getResources()
getstring (r.. Hello_world
//Or supply a string resource to a method that requires a String
textview TextView =new textview (this< Span class= "pun");
Textview. (r.. 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 V Alue.
For example:
<textview
Android:layout_width="Wrap_content"
Android:layout_height="Wrap_content"
Android:text="@string/hello_world"/>
Several ways to use string