When you need to add text in the user interface, Suppose you need to show some text on the button view,you should always specify each string of text in a resource file strings.xml that is located in res/Values. String resources allow you to maintain a single location for all string values, which makes it easier to find and update text.
strings.xml looks like this:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello AuthorCode</string> <string name="app_name">MyProject</string> <string name="ok">OK</string> </resources>
How to use String Resource in main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/ok" /> </LinearLayout>
We are using to set the text of the Textview and button by string resources.