如何用不同的笔触和填充颜色绘制文本?

问题描述:

我想在我的应用中显示如下文字。我正在使用样式 FILL_AND_STROKE Paint 类来实现此目的。但只有一种方法 setColor()可用于设置颜色。

I want to display text as below in my app. I am using Paint class with style FILL_AND_STROKE to achieve this. But only one method setColor() is available to set the color.

如何设置不同的笔触和填充颜色?

How do I set different stroke and fill colors?

内部自定义TextView(在EditText中不起作用):

Inside custom TextView (does not work in EditText):

@Override
public void onDraw(Canvas canvas)
{
    final ColorStateList textColor = getTextColors();

    TextPaint paint = this.getPaint();

    paint.setStyle(Style.STROKE);
    paint.setStrokeJoin(Join.ROUND);
    paint.setStrokeMiter(10);
    this.setTextColor(strokeColor);
    paint.setStrokeWidth(strokeWidth);

    super.onDraw(canvas);
    paint.setStyle(Style.FILL);

    setTextColor(textColor);
    super.onDraw(canvas);
}