remoteview设置渐变色

某些场景如自定义notification设置GradientDrawable效果,需要通过转为bitmap实现,

drawable(包含GradientDrawable )转为bitmap

public Bitmap convertToBitmap(Drawable drawable, int widthPixels, int heightPixels) {
    Bitmap mutableBitmap = Bitmap.createBitmap(widthPixels, heightPixels, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(mutableBitmap);
    drawable.setBounds(0, 0, widthPixels, heightPixels);
    drawable.draw(canvas);

    return mutableBitmap;
}

你可能感兴趣的:(android)