Android Resources Organizing & Accessing 资源的组织和访问
本文参考这里
组织资源(Organize Resources)
略
替代资源(Alternative Resources)
略
访问资源(Accessing Resources)
- 代码中访问资源(Accessing Resources in Code)
生成 R 类,访问res/
目录的文件。
R.raw.mysong
- XML中访问资源(Accessing Resources in XML)
/* strings.xml 文件 */
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="sayhello">Hi friend!</string>
</resources>
/* activity_main.xml 文件 */
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:text="@string/sayhello"
/>
</RelativeLayout>