Android: Using SVG in res leads to error: “The file name must end with .xml or .png”

前端 未结 6 1806
无人共我
无人共我 2020-12-15 08:40

I just updated Android Studio 1.2.1.1 and now gradle got problems with svg in my resources folder. I was always using SVGs with no problem and I hope they will be \"allowed\

6条回答
  •  独厮守ぢ
    2020-12-15 09:13

    Within Android you should be using (XML) Vector Drawable files (they contain the SVG information inside the XML, details: https://developer.android.com/training/material/drawables.html#VectorDrawables).

    Vector Drawables can be downloaded from this repository: https://github.com/google/material-design-icons. Look for the folders called drawable-anydpi-v21 within the icon directories. This folder includes the Vector Drawable files to be placed within the drawable directory of your app.

    Note that working with the Vector Drawable files is only supported for Android 5.0 and higher. In case you need to be compatible with <5.0 Android version I would recommend to make use of this library: https://github.com/trello/victor This library can be used to convert SVG files to drawables in different formats during compilation of your app. Which saves you from having to create and mantain mdpi/hdpi/xhdpi/xxhdpi folders manually.

    In case you name the Vector drawable files and the SVG files equally, you can use both approaches next to each other.

提交回复
热议问题