Android的Canvas.drawTextAndroid、Canvas、drawText

2023-09-12 08:54:10 作者:爸比娃娃

我有一个观点,我跟在OnDraw中(画布油画)方法Canvas对象绘制。我的code是:

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.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。改变了code到:

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

和这一切工作正常现在!

and it all works fine now!!

 
精彩推荐
图片推荐