我正在尝试在我的Android应用中使用VectorDrawables。
我想要从文件系统加载一个xml文件,并获得一个android.graphics.Drawable
实例来在ImageView
中显示它。如果我将xml文件添加到资源目录中,它可以正常工作。但是,当我尝试从文件系统加载它时,我总是得到一个NullPointer。
我当前正在尝试使用Drawable.createFromPath(*文件路径*)
或VectorDrawable.createFromPath(*文件路径*)
来加载文件,但我始终得到NullPointer。该文件存在且是一个有效的xml文件(见下文)。
在adb日志中,我总是得到:
SkImageDecoder::Factory returned null
当我使用mContext.getFilesDir()
时,路径看起来像这样
/data/data/*packagename*/files/*filename*.xml
我还尝试了一些公共文件夹,比如“下载”文件夹。当我使用File.io API检查该文件时,它exists()
,canRead()
和canWrite()
。
更新 这是从Android Dev Pages中提取的XML代码。
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:width="64dp"
android:viewportHeight="600"
android:viewportWidth="600" >
<group
android:name="rotationGroup"
android:pivotX="300.0"
android:pivotY="300.0"
android:rotation="45.0" >
<path
android:name="v"
android:fillColor="#000000"
android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
</group>