我加入的項目(使用圖標)我的菜單是這樣的:編程設置形狀的顏色繪製
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