如何用不同的笔触和填充颜色绘制文本? [英] How to draw text with different stroke and fill colors?
本文介绍了如何用不同的笔触和填充颜色绘制文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的应用中显示如下文字。我正在使用样式 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);
}
这篇关于如何用不同的笔触和填充颜色绘制文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文