如何在自定义视图中填充描边文本?
我准备了一个自定义视图,视图代码是,
mPaint.setDither(true);
mPaint.setColor(0xFFFFFFFF);
mPaint.setTextSize(100);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(2);
protected void onDraw(Canvas canvas) {
canvas.drawText("Android",100,100,mPaint);
}
结果视图是
https://i.sstatic.net/ yDXL3.png
这里我想在“Android”中填充一些颜色。我又准备了一个绘画对象,即
mAlphaInner.setDither(true);
mAlphaInner.setColor(0xFF0000FF);
mAlphaInner.setTextSize(98);
添加到 onDraw() 中,
canvas.drawText("Android",100,100,mPaint);
但视图是
https://i .sstatic.net/oHueB.png
请帮助我如何在“Android”中填充颜色。
I have prepared one custom view that view code is,
mPaint.setDither(true);
mPaint.setColor(0xFFFFFFFF);
mPaint.setTextSize(100);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(2);
protected void onDraw(Canvas canvas) {
canvas.drawText("Android",100,100,mPaint);
}
result view is,
https://i.sstatic.net/yDXL3.png
here i want fill with some color inside "Android". I have prepared one more paint object that is,
mAlphaInner.setDither(true);
mAlphaInner.setColor(0xFF0000FF);
mAlphaInner.setTextSize(98);
added in onDraw(),
canvas.drawText("Android",100,100,mPaint);
but view is ,
https://i.sstatic.net/oHueB.png
please help me how to fill with color inside "Android".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试
mPaint.setStyle(Pain.Style.FILL_AND_STROKE)
编辑:
忘记
Paint.setTextAlign(Paint.Align.CENTER)
会怎样?在两种油漆中What if you would try
mPaint.setStyle(Pain.Style.FILL_AND_STROKE)
EDITED:
Forget about
Paint.setTextAlign(Paint.Align.CENTER)
in both paints使用两种不同的模式绘制两次文本。
Draw your text twice, using two different modes.