SVG support on Android

前端 未结 11 1898
一向
一向 2020-11-28 23:06

Does Android support SVG? any example?

相关标签:
11条回答
  • 2020-11-28 23:44

    Currently some people including me work on it independently.
    You may find working solution in these articles:
      Android. ImageView with SVG Support.
      Android ImageView and Drawable with SVG support

    0 讨论(0)
  • 2020-11-28 23:48

    There is a new library (under active development) androidsvg which allows one to incorporate svg images directly in to projects. It has the advantage of defining an SVGImageView which allows one to incorporate an svg directly in the layout xml.

    Finally, including svg in android is straightforward.

    More details: Stack Overflow post

    0 讨论(0)
  • 2020-11-28 23:49

    The most complete answer is this:

    • The Android 2.x default browser does not natively support SVG.
    • The Android 3+ default browsers DO support SVG.

    To add SVG support to 2.x versions of the platform, you have two basic choices:

    1. Install a more capable browser (like Firefox or Opera Mobile - both support SVG)
    2. Use a JavaScript polyfill that can parse SVG and render it to an HTML5 canvas

    The first option is okay if you're just trying to make SVG work for personal uses or a limited (controllable) set of users. It's not a great option if you want to use SVG while targeting a large, uncontrolled user base.

    In the later case, you want to use a polyfill. There are many JavaScript libraries available today that can prase SVG and render to a canvas. Two examples are:

    • canvg
    • fabric.js

    Using a polyfill, you can render your SVG in a canavs on all versions of Android 2.x.

    For a more complete example of this approach, you can refer to this blog post that discusses the use of the canvg polyfill for making Kendo UI DataViz charts (SVG-based) work on Android 2.x. Hope that helps!

    0 讨论(0)
  • 2020-11-28 23:49

    There is a new open-source library that supports loading and drawing SVG Basic 1.1 files: https://github.com/pents90/svg-android. Performance is good as the actual drawing is handled natively by an android.graphics.Picture object.

    0 讨论(0)
  • 2020-11-28 23:50

    Firefox for Android supports SVG.

    0 讨论(0)
提交回复
热议问题