在xml中储存图片id的引用:
<integer-array name="chose_color">
<item>@drawable/round_corner_color</item>
<item>@drawable/round_corner_color1</item>
<item>@drawable/round_corner_color2</item>
</integer-array>
用getIntArray发现数组中都为0
错误代码:
int[] task = getResources().getIntArray(R.array.background);
for(int i:task){
//结果全为0
System.out.println(task[i]);
}
正确代码:
TypedArray pictures = getResource().obtainTypedArray(R.array.pictures);
Drawable drawable = pictures.getDrawable(0);
网友评论