VectorDrawables在Pre Lollipop上的Android小部件中的具体使用方法

VectorDrawables在Pre Lollipop上的Android小部件中的具体使用方法,android,vector,widget,android-widget,android-vectordrawable,Android,Vector,Widget,Android Widget,Android Vectordrawable,我尝试在我的小部件中使用vector drawable,在棒棒糖前,图像不会显示,因为我尝试以编程方式显示图像bcozapp:srcCompat在小部件中不起作用,基于以下给出的答案: AppCompat 23.2在我的项目中将VectorDrawableCompat与API上的RemoteView(AppWidget)一起使用 remoteViews.setImageViewBitmap(R.id.widget_control, VectorUtil

我尝试在我的小部件中使用vector drawable,在棒棒糖前,图像不会显示,因为我尝试以编程方式显示图像bcozapp:srcCompat在小部件中不起作用,基于以下给出的答案:


AppCompat 23.2在我的项目中将VectorDrawableCompat与API上的RemoteView(AppWidget)一起使用

remoteViews.setImageViewBitmap(R.id.widget_control, VectorUtil
                        .vectorToBitmap(context, R.drawable.chevron_left));
向量:

public static Bitmap vectorToBitmap(Context context, @DrawableRes int resVector) {
    Drawable drawable = AppCompatResources.getDrawable(ctx, resVector);
    Bitmap b = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    drawable.setBounds(0, 0, c.getWidth(), c.getHeight());
    drawable.draw(c);
    return b;
}
而且效果很好


但正如我在stacktrace中看到的,向量有问题,因为向量的解析器无法读取标记。验证向量。

在我的项目中,它是这样的:

remoteViews.setImageViewBitmap(R.id.widget_control, VectorUtil
                        .vectorToBitmap(context, R.drawable.chevron_left));
向量:

public static Bitmap vectorToBitmap(Context context, @DrawableRes int resVector) {
    Drawable drawable = AppCompatResources.getDrawable(ctx, resVector);
    Bitmap b = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    drawable.setBounds(0, 0, c.getWidth(), c.getHeight());
    drawable.draw(c);
    return b;
}
而且效果很好

但正如我在stacktrace中看到的,向量有问题,因为向量的解析器无法读取标记。验证你的向量

remoteViews.setImageViewBitmap(R.id.widget_control, VectorUtil
                        .vectorToBitmap(context, R.drawable.chevron_left));
public static Bitmap vectorToBitmap(Context context, @DrawableRes int resVector) {
    Drawable drawable = AppCompatResources.getDrawable(ctx, resVector);
    Bitmap b = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    drawable.setBounds(0, 0, c.getWidth(), c.getHeight());
    drawable.draw(c);
    return b;
}