小编Jay*_*_DK的帖子

是否可以从文件系统(*.xml文件)创建VectorDrawable

我想在我的Android应用程序中使用VectorDrawables.
我想从文件系统加载一个xml文件,并获取一个实例android.graphics.Drawable来显示它ImageView.如果我将xml文件添加到Resources目录,它可以工作.但是当我尝试从文件系统加载它时,我总是得到一个NullPointer.

我目前正在尝试通过Drawable.createFromPath(*Path to File*)或加载文件 VectorDrawable.createFromPath(*Path to File*),但我一直在获取NullPointer.文件存在且是一个有效的xml文件(见下文).

在adb日志中我总是得到:

SkImageDecoder::Factory returned null
Run Code Online (Sandbox Code Playgroud)

当我使用 mContext.getFilesDir()Path看起来像

/data/data/*packagename*/files/*filename*.xml
Run Code Online (Sandbox Code Playgroud)

我还尝试了一些像"下载"这样的公共文件夹.当我用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>
Run Code Online (Sandbox Code Playgroud)

xml android android-vectordrawable

6
推荐指数
2
解决办法
1690
查看次数

标签 统计

android ×1

android-vectordrawable ×1

xml ×1