android - VectorDrawable 无法在 API 23 上正确呈现

标签 android android-vectordrawable

我尽可能用 VectorDrawables 替换我的所有图标。但我注意到其中一些在 API 23 上无法正确渲染,而且颜色似乎正在渗出。这 3 个中的一个渲染得很好。这是来自 isolated project 的屏幕截图我创建了:

enter image description here

在 API 21 上看起来非常好:

enter image description here

The source code of sample app is here

我在 ImageView 上使用 AppCompat 24.0.0,app:srcCompat 并设置了 vectorDrawables.useSupportLibrary=true。我还尝试了使用目标 23 的 AppCompat 23.4.0。但是,如果我删除 appCompat 并将 minSdkVersion 设置为 21 并使用 native 矢量支持,结果不会改变。 IDE 不会提示任何不受支持的东西。我如何找出问题所在?是平台bug吗?有什么解决方法吗?

最佳答案

我只在 API 23 上遇到了完全相同的问题。我正在动态设置我的 ImageView 源,而不是在 xml 中。我意识到问题在于我正在做:

Drawable show = getContext().getResources().getDrawable(resourceId);

当我应该做的时候:

Drawable show = AppCompatResources.getDrawable(getContext(), resourceId);

我希望这对某人有帮助!

关于android - VectorDrawable 无法在 API 23 上正确呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38184911/

相关文章:

android - Activity 似乎是在应用程序对象之前创建的

java - 如何向 x 次 TCP 客户端请求 TCP 服务器数据?

android - 在运行时从 SVG 文件创建 VectorDrawable

android - 什么时候使用 VectorDrawable?

安卓工作室 1.5.1 : Could not find property 'vectorDrawables'

带有 VectorDrawables srcCompat 的 Android Selector Drawable

java - 使用谷歌地图javascript api v3在谷歌地图上添加多个目的地

android - 使用 AppCompat-v7 21 在操作栏/工具栏中显示图标

java - 图表引擎,图表内嵌另一个图表

android - 尝试添加新矢量 Assets 时无法生成预览