04項目的目錄結構分析與資源引用
普通字符串資源:
布局資源:
案例:
main.xml:
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="240dp"
android:text="加油吧!少年!"
/>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/msg"
android:onClick="test"
/>
R.java:
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int button1=0x7f050001;
public static final int textView1=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040000;
public static final int hello=0x7f040001;
public static final int msg=0x7f040002;
}
}
Strings.xml:
<resources>
<string name="app_name">ONEAndroid</string>
<string name="hello">Hello World, ONEAndroidActivity!</string>
<string name="msg">welcome,weini!</string>
</resources>
ONEAndroidActivity.java:
public void test(View view){
TextView textView1=(TextView) findViewById (R.id.textView1);
textView1.setText("The greatest test of courage on earth is to bear defeat without losing heart\n世界上對勇氣的最大考驗是忍受失敗而不喪失信心。");
Toast.makeText(ONEAndroidActivity.this, "點擊button",Toast.LENGTH_SHORT).show();
}
運行結果:
點擊按鈕前:
點擊按後:
中英文時候的選擇:
圖示:
04項目的目錄結構分析與資源引用