我加入的项目(使用图标)我的菜单是这样的:编程设置形状的颜色绘制
subMenu.add(user.getName()).setIcon(R.drawable.user_bg);
的user_bg
绘制的布局是这样的:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/user_color">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#000000"
/>
<size
android:width="100dp"
android:height="100dp"
/>
</shape>
</item>
<item
android:drawable="@drawable/user"
android:adjustViewBounds="true"
android:scaleType="fitXY"
/>
</layer-list>
如何可以在添加新项目后以编程方式更改可绘制的颜色(#000000
)?
如果我有一个'for'循环,增加了多个项目的菜单,其中每个项目有它自己的独立颜色。我在'for'循环中添加了你的代码,但是它将所有项目的颜色设置为循环中最后一种颜色。 – user5403695