如何在自定义视图中填充描边文本?

发布于 2024-12-22 12:33:44 字数 982 浏览 3 评论 0原文

我准备了一个自定义视图,视图代码是,

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧街凉风 2024-12-29 12:33:44

如果您尝试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

人间☆小暴躁 2024-12-29 12:33:44

使用两种不同的模式绘制两次文本。

        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);

        mAlphaInner.set(mPaint);  //Set the same text size!
        mAlphaInner.setColor(0xFF0000FF);
        mAlphaInner.setStyle(Paint.Style.FILL_AND_STROKE);

    protected void onDraw(Canvas canvas) {
      canvas.drawText("Android",100,100,mAlphaInner);
      canvas.drawText("Android",100,100,mPaint);
   }

Draw your text twice, using two different modes.

        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);

        mAlphaInner.set(mPaint);  //Set the same text size!
        mAlphaInner.setColor(0xFF0000FF);
        mAlphaInner.setStyle(Paint.Style.FILL_AND_STROKE);

    protected void onDraw(Canvas canvas) {
      canvas.drawText("Android",100,100,mAlphaInner);
      canvas.drawText("Android",100,100,mPaint);
   }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文