2015年1月2日金曜日

ウィジェット上のtextの指定箇所

Androidアプリは、〈ボタン〉とかはオブジェクトじゃなくてウィジェット、って言うのかな?
んで、たとえば〈TextView〉とかに表示するテキストをプロパティの〈text〉で直接指定もできるんだけど、strings.xmlにまとめて書き留めて、こちらの情報を呼び出す方法もあるらしい。


・strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">MyFirstApp05</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>

</resources>


・activity_main.xml
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


strings.xmlで <string name="hello_world">Hello world!</string> と、指定したものを、 android:text="@string/hello_world" として呼び出している模様。

0 件のコメント:

コメントを投稿