SVG in DivKit for Android!

SVG in DivKit for Android!

DivKit

DivKit for Android, starting from version 30.0, supports the SVG format for image and background elements!

No additional configuration is required to load SVGs. Simply pass links to .svg files in image_url , just as you would with raster images. Additionally, you can pass base64-encoded vector images in the preview field. (Make sure the string includes the correct base64 prefix: data:image/svg+xml;base64, )

SVG loading is overridden by default for all loaders, including custom ones. If your custom DivImageLoader supports loading vector images and you want DivKit to use it instead of the standard one, override the method hasSvgSupport() in your DivImageLoader to return true . Then, when attempting to load an SVG image, your loader's loadImage() method will be called, just as it is for regular raster images.


Compatibility

We use the androidsvg library to work with SVGs. You can read about which elements are supported by the library here.

We have tested it on API down to 24, so there should be no issues with older devices.


Limitations when working with vector images

  • Color filters and blur ( tint_color and filter -> blur modifiers) are not supported for SVGs in the image element.
  • Transparency and blur ( alpha and filter -> blur modifiers) are not supported for SVGs in the background element.

However, this does not mean the image will not be displayed. It will simply be rendered into a Bitmap with the dimensions specified in the root structure of the SVG ( <svg width="100" height="100"> ), with all the applied modifiers.


Report Page