Android Canvas.drawText [英] Android Canvas.drawText

查看:36
本文介绍了Android Canvas.drawText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,我在 onDraw(Canvas canvas) 方法中使用 Canvas 对象进行绘图.我的代码是:

I have a view, I'm drawing with the Canvas object in the onDraw(Canvas canvas) method. My code is:

Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setStyle(Style.FILL);
canvas.drawPaint(paint);

paint.setColor(android.R.color.black);
paint.setTextSize(20);
canvas.drawText("Some Text", 10, 25, paint);

问题是文本没有通过背景显示,我做错了什么?如果我删除 canvas.drawPaint(paint) 和 paint.setColor(android.R.color.black) 你可以在屏幕上看到文本.....

The problem is the text doesn't show through the background, what am I doing wrong? If I remove the canvas.drawPaint(paint) and paint.setColor(android.R.color.black) you can see the text on the screen.....

推荐答案

解决了这个问题,结果是 android.R.color.black 与 Color.BLACK 不同.将代码更改为:

Worked this out, turns out that android.R.color.black is not the same as Color.BLACK. Changed the code to:

Paint paint = new Paint(); 
paint.setColor(Color.WHITE); 
paint.setStyle(Style.FILL); 
canvas.drawPaint(paint); 

paint.setColor(Color.BLACK); 
paint.setTextSize(20); 
canvas.drawText("Some Text", 10, 25, paint); 

现在一切正常!!

这篇关于Android Canvas.drawText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆