gpt4 book ai didi

android - VectorDrawableCompat.create 无法在旧设备上从 vector.xml 创建图像

转载 作者:行者123 更新时间:2023-11-30 01:18:58 27 4
gpt4 key购买 nike

我使用这段代码来支持旧设备上的矢量图像:

VectorDrawableCompat.create(context.getResources(), resId, context.getTheme());

但目前它不起作用(我为 Android Studio 2.1.1 安装了一些更新)

我的毕业典礼:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 23
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

dataBinding {
enabled = true
}

aaptOptions {
additionalParameters "--no-version-vectors"
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.5.0'
}

矢量资源示例:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M3.9,12c0,-1.71 1.39,-3.1 3.1,-3.1h4L11,7L7,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5h4v-1.9L7,15.1c-1.71,0 -3.1,-1.39 -3.1,-3.1zM8,13h8v-2L8,11v2zM17,7h-4v1.9h4c1.71,0 3.1,1.39 3.1,3.1s-1.39,3.1 -3.1,3.1h-4L13,17h4c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5z"/>
</vector>

它打印错误:

android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/ic_insert_link_24.png from xml type xml resource ID #0x7f020062 at android.content.res.Resources.loadXmlResourceParser(Resources.java:3045) at android.content.res.Resources.loadXmlResourceParser(Resources.java:2992) at android.content.res.Resources.getXml(Resources.java:1772) at android.support.graphics.drawable.VectorDrawableCompat.create(VectorDrawableCompat.java:408)

谁知道修复这个bug?
附言我知道 ImageView 和其他一些 View 默认支持 VectorDrawableCompat 但我需要获取 Drawable 才能在 Canvas 上绘制它

最佳答案

看错误应该说点什么。

android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/ic_insert_link_24.png from xml type xml resource ID #0x7f020062

您正在使用 ic_insert_link_24.png 这不应该出现在 drawable 文件夹 中所以出现此错误尝试将它放在 drawable 文件夹并检查它。

关于android - VectorDrawableCompat.create 无法在旧设备上从 vector.xml 创建图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37403527/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com