VectorDrawable无法在API 23上正确呈现 [英] VectorDrawable not rendering correctly on API 23
问题描述
我将尽可能用VectorDrawables替换所有图标.但是我注意到其中一些在API 23上无法正确渲染,并且颜色似乎正在渗出.这3种效果之一可以很好地渲染.这是我创建的 隔离项目 的屏幕截图:
I am replacing all my icons with VectorDrawables wherever possible. But I noticed a couple of them don't render correctly on API 23 and the color seems to be bleeding out. One of these 3 renders fine. Here's a screenshot from a isolated project I created:
在API 21上看起来非常不错:
Looks perfectly fine on API 21:
我在ImageView上使用AppCompat 24.0.0,app:srcCompat,并设置了vectorDrawables.useSupportLibrary = true.我还使用目标23尝试了AppCompat 23.4.0.但是,如果删除appCompat并将minSdkVersion设置为21并使用本机矢量支持,结果将不会改变. IDE不会抱怨任何不受支持的东西.我如何找出问题所在?是平台错误吗?有什么解决方法吗?
I am using AppCompat 24.0.0, app:srcCompat on ImageView and have set vectorDrawables.useSupportLibrary=true. I also tried AppCompat 23.4.0 with target 23. However, if I remove appCompat and set minSdkVersion to 21 and use native vector support, the results don't change. The IDE doesn't complain of anything being unsupported. How do I figure out what's the problem? Is it a platform bug? Are there any workarounds?
推荐答案
我仅在API 23上遇到了完全相同的问题.我正在动态设置ImageView源,而不是在xml中.我意识到问题在于我在做什么:
I had exactly the same problem on API 23 only. I was setting my ImageView source dynamically, rather than in xml. I realised the problem was that I was doing:
Drawable show = getContext().getResources().getDrawable(resourceId);
当我应该做的时候:
Drawable show = AppCompatResources.getDrawable(getContext(), resourceId);
我希望这对某人有帮助!
I hope this helps someone!
这篇关于VectorDrawable无法在API 23上正确呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!