<resources>
<!-- Used in View/Spinner1.java -->
<string-array name="colors">
<item>red</item>
<item>orange</item>
<item>yellow</item>
<item>green</item>
<item>blue</item>
<item>violet</item>
</string-array>
</resources>
//java code
Resources res = this.getResources();
String[] arr = res.getStringArray(R.array.colors);
for(int i=0; i<arr.length-1; i++) {
Log.i("TEST", arr[i]);
}
本文介绍了一种在Android应用程序中定义和使用颜色数组资源的方法。通过XML文件定义了一个包含多种颜色名称的字符串数组,并展示了如何在Java代码中访问并遍历这个数组。此方法有助于提高代码的可维护性和资源管理效率。
3634

被折叠的 条评论
为什么被折叠?



