首先 在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();
本文介绍如何在Android应用中使用XML配置文件定义抽屉菜单的默认图标,并通过代码获取这些图标资源。

3887

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



