以编程方式更改绘制颜色颜色、方式

2023-09-12 07:29:26 作者:Guardianship 相守

我想通过code改变白色标记图像的颜色。我已阅读了code以下应改变颜色,但我的标记仍然是白色的。

I'm trying to change the color on a white marker image by code. I have read that the code below should change the color, but my marker remains white.

Drawable.setColorFilter( 0xffff0000, Mode.MULTIPLY )

我错过了什么?是否有任何其他的方式来改变我可绘设在我的资源文件夹的颜色?

Did I miss something? Is there any other way to change colors on my drawables located in my res folder?

推荐答案

试试这个:

Drawable mDrawable = context.getResources().getDrawable(R.drawable.balloons); 
mDrawable.setColorFilter(new 
PorterDuffColorFilter(0xffff00,PorterDuff.Mode.MULTIPLY));