首先 在xml中这样配置
<array name = "drawer_icon_normal">
<item>@drawable/drawer_home_normal</item>
<item>@drawable/drawer_follow_normal</item>
<item>@drawable/drawer_collect_normal</item>
<item>@drawable/drawer_register_normal</item>
<item>@drawable/drawer_explore_normal</item>
</array>
然后在代码中调用如下:
TypedArray array = context.getResources().obtainTypedArray(R.array.drawer_icon_normal);
for (int i= 0; i< array.length(); i++) {
drawables_normal[i$] = array.getResourceId(i$, R.drawable.default_profile);
}
array.recycle();