How do I tint this PictureDrawable?

好久不见. 提交于 2019-12-01 02:25:15

问题


I am using svgandroid to generate PictureDrawables from SVG raw resources. However, I can't seem to be able to apply a color filter on a drawable created this way.

The old code using PNGs

icon = getResources().getDrawable(R.drawable.ic_braille);
icon.setColorFilter(0x88880000, Mode.MULTIPLY);
((ImageView)v.findViewById(R.id.icon)).setImageDrawable(icon);

works, but

icon = SVGParser.getSVGFromResource(getResources(), R.raw.ic_braille).createPictureDrawable();
icon.setColorFilter(0x88880000, Mode.MULTIPLY);
((ImageView)v.findViewById(R.id.icon)).setImageDrawable(icon);

does not. I have tried applying the color filter on the Drawable, on the ImageView (after setting the drawable to it), through XML, even on the Drawable after setting it as the drawable of the ImageView, either is OK for the PNG but neither works for the PictureDrawable. Replacing setImageDrawable by setBackgroundDrawable, as suggested by some, does not render the drawable at all. I am running the code on Androids 1.6, 2.3, 4.0, no difference. I have checked the source of the SVG library, it does not touch color filters in any point. What am I doing wrong? Is tinting unavailable for some kinds of drawables?


回答1:


Use this fork of svg-android: https://github.com/japgolly/svg-android

It supports ColorFilters.



来源:https://stackoverflow.com/questions/13655917/how-do-i-tint-this-picturedrawable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!