在res/values/strings.xml文件中,有如下代码:
<resources>
<string name="app_name">HelloWorld</string>
</resources>
这里定义了一个应用程序名的字符串,引用它的方式有两种:
- 在代码中可以通过R.string.app_name来获得该字符串的引用
- 在XML中可以通过@string/app_name来获得该字符串的引用
以上的string部分是可以被替换的,引用的什么资源就换成什么。
例如,在AndroidManifest.xml文件中有如下代码:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
…
</application>
如上所示,HelloWorld项目的应用图标是通过android:icon属性指定的,应用名称则是android:label属性指定的。