下面的範例, 我仍是將 <string> 放在 strings.xml, 但你也可獨立另一個 xml 檔做為文字定義檔:


Java 程式引用語法
R.string.stringName
this.getString(R.string.stringName)
this.getResources.getString(R.string.stringName)
如: setText( R.string.hello );
如: setText( "Message: " + this.getString(R.string.hello) );
XML 引用語法
@string/stringName
如: android:Text="@string/hello"