Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何以编程方式在圆形图像视图中设置自定义背景色_Android - Fatal编程技术网

Android 如何以编程方式在圆形图像视图中设置自定义背景色

Android 如何以编程方式在圆形图像视图中设置自定义背景色,android,Android,我已经设置了一个圆形的图像视图,但我不知道如何为它设置背景色。我尝试了“设置背景”方法来填充图像中的颜色 public Bitmap roundCornerImage(Bitmap raw, float round) { int width = raw.getWidth(); int height = raw.getHeight(); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB

我已经设置了一个圆形的图像视图,但我不知道如何为它设置背景色。我尝试了“设置背景”方法来填充图像中的颜色

public Bitmap roundCornerImage(Bitmap raw, float round) {
    int width = raw.getWidth();
    int height = raw.getHeight();
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    canvas.drawARGB(0, 0, 0, 0);
    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.parseColor("#000000"));
    final Rect rect = new Rect(0, 0, width, height);
    final RectF rectF = new RectF(rect);
    canvas.drawRoundRect(rectF, round, round, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(raw, rect, rect, paint);
    return result;
}
或者更改父布局的背景色

canvas.drawARGB(0, 0, 0, 0)
这条线将绘制一幅黑色的画布。如果只想更改颜色,请更改rgb值。例如

canvas.drawARGB(255, 0, 0, 0)

将绘制一个红色位图画布。

您可以发布您尝试过的内容吗?检查我需要为我插入的图像设置背景色您是否尝试过在圆形图像视图上设置这些属性?是的@Sanoop我有tiredI没有问您@Kovart您是否尝试过在圆形图像视图上设置这些属性第一个实际上什么也不画,因为使用ARGB意味着将alpha设置为0
canvas.drawARGB(0, 0, 0, 0)
canvas.drawARGB(255, 0, 0, 0)