我如何着色这个PictureDrawable? [英] How do I tint this PictureDrawable?

查看:279
本文介绍了我如何着色这个PictureDrawable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 svgandroid 来生成 PictureDrawable - 从SVG原料资源。不过,我似乎无法能够应用的彩色滤光片上创建这样一个绘制。

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.

使用PNG格式的旧code

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);

的作品,但

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

没有。我试图施加在绘制对象的滤色器,关于ImageView的,通过XML,即使在绘制对象其设置为ImageView的的可拉伸后(可提拉设置到它之后),或者是为PNG行但既不作品该PictureDrawable。更换 setImageDrawable setBackgroundDrawable ,所建议的一些,不呈现绘制的。我的机器人1.6,2.3,4.0,没有什么区别运行code。我已经检查了SVG库的源代码,它不触及任何一点彩色滤光片。我究竟做错了什么?是无法着色为某些类型的可绘制的?

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?

推荐答案

使用这种叉SVG-的android: https://github.com/japgolly/svg-android

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

它支持ColorFilters。

It supports ColorFilters.

这篇关于我如何着色这个PictureDrawable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆