サンプルアプリの res/layout/activity_main.xml の中に以下のコードがあります。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
![]() |
| @string/hello_world が Hello world! になっている |
一方 res/values/strings.xml はこんなかんじ
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">String</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
</resources>
例のごとく R.java の中に参照が自動で作られています
public static final class string {
public static final int action_settings=0x7f050001;
public static final int app_name=0x7f050000;
public static final int hello_world=0x7f050002;
}
@string/hello_world は R.java の string の hello_world に関連付けられたテキストを参照しています。
テキストは別の場所に定義しておいて、使うときにそれを参照するようです。
言語別に文字列を定義しておいて、実行時の環境に合わせて切り替えたりするらしいです。
確かRPGツクールアドバンスもこんな感じでメッセージは別で作る仕様だった気がします。

0 件のコメント:
コメントを投稿