Java 自定义笔划以具有边框和填充

Java 自定义笔划以具有边框和填充,java,android,Java,Android,如何使用填充颜色和(不同颜色)边框绘制笔划 e、 g.我想要这样的东西: 我试着创作了两种颜料——一种是笔划风格,另一种是填充风格,但我不喜欢 strokePaint = new Paint(); strokePaint.setStyle(Paint.Style.STROKE); strokePaint.setColor(Color.parseColor("#A3A3A3")); fillPaint = new Paint(); fillPaint.setStyle(Paint.Style.F

如何使用填充颜色和(不同颜色)边框绘制笔划

e、 g.我想要这样的东西:

我试着创作了两种颜料——一种是笔划风格,另一种是填充风格,但我不喜欢

strokePaint = new Paint();
strokePaint.setStyle(Paint.Style.STROKE);
strokePaint.setColor(Color.parseColor("#A3A3A3"));
fillPaint = new Paint();
fillPaint.setStyle(Paint.Style.FILL);
fillPaint.setColor(Color.WHITE);

canvas.drawPath(totalPath, strokePaint);
canvas.drawPath(totalPath, fillPaint);
没有达到预期效果,看起来很糟糕


这可能吗?

我想出来了。诀窍是画两次,一次是背景层,厚1-2像素,然后是前景层

i、 e:

strokePaintBackground = new Paint(Paint.ANTI_ALIAS_FLAG);
strokePaintBackground.setStyle(Paint.Style.STROKE);
strokePaintBackground.setColor(Color.BLACK);
strokePaintBackground.setStrokeWidth(8);
strokePaintBackground.setPathEffect(new DashPathEffect(new float[]{30, 15}, 0));
strokePaintBackground.setStrokeCap(Paint.Cap.ROUND);
strokePaintBackground.setStrokeJoin(Paint.Join.ROUND);

strokePaintForground = new Paint(Paint.ANTI_ALIAS_FLAG);
strokePaintForground.setStyle(Paint.Style.STROKE);
strokePaintForground.setColor(Color.WHITE);
strokePaintForground.setStrokeWidth(6);
strokePaintForground.setPathEffect(new DashPathEffect(new float[]{30, 15}, 0));
strokePaintForground.setStrokeCap(Paint.Cap.ROUND);
strokePaintForground.setStrokeJoin(Paint.Join.ROUND);

canvas.drawPath(totalPath, strokePaintBackground);
canvas.drawPath(totalPath, strokePaintForground);

你想让笔划和填充的颜色不同吗?是的,我想让它看起来像线条周围有一个边框。可能的重复。你能给问题添加一个截图吗?想知道能帮助你看起来有多糟糕。也许你调用drawPath函数的顺序不对?尝试运行canvas.drawPath(totalPath,fillPaint)before
canvas.drawPath(totalPath,strokePaint)