使用fillType ="evenOdd";在Android 21上 [英] Use fillType="evenOdd" on Android 21

查看:569
本文介绍了使用fillType ="evenOdd";在Android 21上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要包含在Android项目中的SVG图片.

该项目的minSdk版本为9.AndroidStudio正在为SVG生成PNG文件.

但是,对于API 21 +,Android Studio在drawable-anydpi-v21资源文件夹中包含SVG.

这意味着任何运行API 21及更高版本的设备都将使用SVG而不是PNG.

这就是问题所在:我的SVG需要android:fillType="evenOdd".

正确生成了PNG,但对于SVG,由于该属性是API 24+,因此在API 21设备上将被忽略,并且图像看起来像是填充的,而不是像线框一样的图像.

无论如何,是否有说服Android Studio仅包含PNG并完全删除SVG?

还有其他解决方案吗?

解决方案

解决方案1 ​​

素描中的平面图像,并使用

我在Sketch中打开了SVG图标,并检查了图标顶部的孔.如预期的那样,它使用fill-rule:evenodd属性.现在,我必须更改填充规则以使用"nonzero"属性.如何?选择路径.右侧的填充"属性中有一个设置图标.单击它,然后选择非零".

从主菜单中选择图层"→路径"→逆序".我在图标顶部又找到了一个漏洞,并且在应用程序中也有一个漏洞.

详细信息

I have an SVG image that I want to include in an Android project.

The minSdk version for the project is 9. Android Studio is generating PNG files for the SVG.

However, for API 21+, Android studio includes the SVG in a drawable-anydpi-v21 resource folder.

That means that any device running API 21 and up will use the SVG instead of the PNGs.

And that is the problem: my SVG requires android:fillType="evenOdd".

The PNG are properly generated, but for the SVG, because that attribute is API 24+, it is ignored on API 21 devices, and the image appears filled instead of being a wireframe-like image.

Is there anyway to convince Android studio to only include the PNG and drop the SVG completely?

Is there an other solution for this?

解决方案

Solution 1

Flattern image in Sketch and use this site to convert SVG to xml for Android

Solution 2

I use nonZero instead of evenOdd and open it in Sketch to reverse Order after reverse it will change pathData and remove android:fillType and everything work fine on Android 21+.

Solution 3

PNG

TLDR

After some research I found that there are two fill-rule property methods for Vector graphics, SVGs, the "evenodd" vs "nonzero"

I opened the SVG icon in Sketch and inspected the hole at the top of the icon. As expected it uses fill-rule:evenodd property. Now I have to change the fill-rule to use "nonzero" property. How? Select the path. In the right side, there is a settings icon at the "Fills" property. Click it and choose "non-zero".

From the main menu, choose Layer → Paths → Reverse Order. I got the hole back at the top of the icon and got the hole in the app, too.

For more detail

这篇关于使用fillType ="evenOdd";在Android 21上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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