View on GitHub

AndroidSVG

SVG rendering library for Android

How to change colours at render time

The feature requires version 1.3 or later.

Version 1.3 adds the ability to apply extra custom CSS while rendering an SVG. The exact method depends on whether you are rendering yourself, or using the SVGImageView custom widget.

When rendering yourself

You can provide extra CSS rules via the RenderOptions parameter to the SVG.renderToX() methods.

String  blueEyes = "#eyes { fill: blue; }";

RenderOptions  renderOpts = RenderOptions.create().css( blueEyes );
svg.renderToCanvas(bmcanvas, renderOpts);

When using SVGImageView

You can use the css custom attribute to provide extra CSS

<com.caverock.androidsvg.SVGImageView
    android:id="@+id/imageView1"
    android:layout_width="100dp"
    android:layout_height="100dp"
    app:svg="my_svg_file.svg" />
    app:css="rect.red { fill: red; } path:last-child { stroke: blue; }" />

Or you can do it in code by calling the SVGImageView.setCSS() method.

SVGImageView  svgImageView = (SVGImageView) findViewById(R.id.my_svg)
svgImageView.setCSS("rect:nth-child(odd) { fill: green; }");