Android_资源访问

字符串(string)资源

1.res/values 目录下 strings.xml

根元素是 <resources></resources> 

<string name></string>  name 属性用于指定字符串的名称 内容为字符串资源内容

<resources>
  <string name="app_name">MyDemo</string>
</resources>

2.使用字符串资源

在java文件使用字符串资源的语法

[<package>.]R.string.字符串名
// 例如获取名称为introduce的字符串
getResource().getString(R.string.introduce)

在xml文件

@[<package>:]string/字符串名

<TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/introduce"
/>

color 资源  如上

<resources>
  <color name="title">#66ff0000</color>
</resources></

Guess you like

Origin blog.csdn.net/weixin_38107457/article/details/120557958