<string-array name="sample_names"> <item>foo</item> <item>bar</item> <item>baz</item> </string-array>@H_502_7@
JAVA@H_502_3@
String[] names = getResources().getStringArray(R.array.sample_names);@H_502_7@
<integer-array name="sample_ids"> <item>1</item> <item>2</item> <item>3</item> </integer-array>
JAVA@H_502_3@
int[] ids = getResources().getStringArray(R.array.sample_ids);@H_502_7@
Drawable 数组@H_502_7@ XML@H_502_3@
<array name="sample_images"> <item>@drawable/title</item> <item>@drawable/logo</item> <item>@drawable/icon</item> </array>
@H_502_3@
JAVA@H_502_3@
TypedArray images = getResources().obtainTypedArray(R.array.sample_images); Drawable drawable = images.getDrawable(0);@H_502_7@
Color 数组@H_502_7@ XML@H_502_3@
<array name="sample_colors"> <item>#FFFF0000</item> <item>#FF00FF00</item> <item>#FF0000FF</item> </array>@H_502_7@
JAVA@H_502_3@
TypedArray colors = getResources().obtainTypedArray(R.array.sample_colors); int color = colors.getColor(0,0);// 参数分别为下标和默认值@H_502_7@
说明:Android 可以通过 xml 格式的资源文件来声明与定义各种类型的数组。这样做的好处包括可以根据不同语言/硬件规格等条件分配不同的数组。@H_502_3@